469,325 Members | 1,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

How does a parent know if one if its children finished executing?

78
Hello guys.
This time, i need to implement waitpid in order to know if one of the children of a parent has finished executing. The assignment requires me to run a limited number of child processes. Then if max is reached and one more is asked to run by the user from the command line, the parent must wait and see if there is a free spot. (in the array of children)
Now i know i have to use waitpid somewhere, but using it as: wait child1, waitchild2....will wait for all. I need to wait for 1. The thing is the child will excute another program, meaning it will replace all the code after fork(). So i have no control over the communication between the parent and child, i.e. if i say x = execvp(), this will only be executed in the child, so the parent can't know the return value inorder to check for return values to find a free spot.

Now the solution i've come up with is by forking 2 times for each child, one for the child to run in, and another for parallelly executing waitpid until this child exits, and notifying the parent. I haven't implemented this yet, i just want to know if i'm way off the normal solution path.

Thanks guys.
Apr 4 '07 #1
1 1323
Sebouh
78
It turns out i WAS far from the right path.
My method was too complicated and less effective then using a simple wait(&status).
Damn it! I've wasted my time trying my method, while the answer was right there. Stupid!
Apr 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Dhruv | last post: by
2 posts views Thread by dannielum | last post: by
reply views Thread by Karthick Kumar | last post: by
6 posts views Thread by Edwinah63 | last post: by
10 posts views Thread by Goran Djuranovic | last post: by
3 posts views Thread by xmail123 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.