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.