LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-12-2012, 07:20 AM   #1
muhteremmuho
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Rep: Reputation: Disabled
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;
   }
   }
 
Old 12-12-2012, 07:59 AM   #2
muhteremmuho
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
no help?
never thought of this, while being a Member
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
parent process to wait foe child process to comelet priyas Linux - Kernel 2 03-01-2012 08:52 AM
BASH: Waiting for a process to end, problem with wait patolfo Linux - General 2 03-19-2010 11:54 PM
How to wait for the process and know if the exit code of the sub process williamhomanchun Linux - General 10 08-11-2008 01:32 PM
Fortran and linux: Wait for process completion cooln Programming 3 07-23-2007 09:04 AM


All times are GMT -5. The time now is 02:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration