Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fork() & wait() 1

Status
Not open for further replies.

cmancre

Programmer
Joined
Jan 30, 2005
Messages
35
Location
PT
Hello
code:

while(condition){
pID=fork();
if(!pID){
/* do something */
exit(number);
}
}
wait(number);

Imagine that my while loop creats 4 childs processes. The execution time of each child are diferent, so child nº2 could end first than child nº1. My question is, how my parent process waits for all childs?
 
You need to wait (if you want to wait) for each child process - you cannot (well you can) wait for just one child and hope to catch the other three !

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Read the manual page for waitpid() and study which magic values allow you to wait for any child.

If you have 4 children, waitpid() 4 times.


--
 
Status
Not open for further replies.

Similar threads

  • Locked
  • Question Question
Replies
1
Views
236
  • Locked
  • Question Question
Replies
4
Views
218
  • Locked
  • Question Question
Replies
3
Views
230
  • Locked
  • Question Question
Replies
4
Views
239

Part and Inventory Search

Sponsor

Back
Top