....
....
if(*cmd[0]=='/'){
[b]if(as==0){ //I control as' value here.I want rocess to wait the child when as=0.
wait(NULL); //When as int equal to zero ,the code wont run the if statement so wait(NULL) wont work
}[/b] // But this wait(NULL) always runs.Im not sure how the wait function does
if (childpid == -1) {
perror("Failed to fork\n");
return 1; }
if (childpid == 0){
execl(cmd[0],cmd[1],cmd[2],cmd[3],cmd[4],cmd[5],cmd[6],cmd[7],cmd[8],cmd[9],cmd[10],cmd[11],cmd[12],cmd[13],cmd[14],cmd[15],cmd[16],cmd[17],cmd [18],cmd[19],cmd[20],cmd[21],cmd[22],cmd[23],cmd[24],cmd[25],cmd[26],cmd[27],cmd[28],cmd[29],cmd[30],NULL);
perror("Child failed to execl\n");
}
if (childpid != wait(NULL)) {
perror("Parent failed to wait due to signal or error\n");
return 1;
}
as=0;
}
.....
.....
Linux processes(wait function)
Page 1 of 11 Replies - 625 Views - Last Post: 13 December 2012 - 01:00 AM
#1
Linux processes(wait function)
Posted 11 December 2012 - 12:01 PM
Hi all,Im beginner at Linux programming.I write C language .My problem is about waiting child process.I know 'wait' function waits the child.In the code, parent always waits but I dont want this.Parent must wait when 'as' is equal to zero.Parent must not wait when 'as' is greater than zero.The part of the code is below:
Replies To: Linux processes(wait function)
#2
Re: Linux processes(wait function)
Posted 13 December 2012 - 01:00 AM
If add as == 0 to the if (wait), then the wait is only called when as is zero.
23 if (as == 0 && childpid != wait(NULL))
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|