LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Linux process(problem with wait) (https://www.linuxquestions.org/questions/linux-general-1/linux-process-problem-with-wait-4175441122/)

muhteremmuho 12-12-2012 07:20 AM

Linux process(problem with wait)
 
Hi.I am beginner a Linux.I use C language & fedora.my problem is about wait() function.I know this function waits the child's terminate to continue.I use wait(NULL) and parent waits the child.but I want the parent to wait the child when 'as' equal to zero.If 'as' isnt equal to zero ,the parent(in my code it is main) must not wait the child.But main always waits to continue.Where is the problem?
Code:

...
...
pid_t childpid;
childpid = fork();
int status;


if(*cmd[0]=='/'){

if(as==0){
wait(NULL);
}

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;
  }
  }


muhteremmuho 12-12-2012 07:59 AM

no help? :(
never thought of this, while being a Member


All times are GMT -5. The time now is 07:44 AM.