http://qs321.pair.com?node_id=99455


in reply to Proper Forking

In the child process you:
sleep 1 until getppid == 1;
which will loop until the child processes parent is pid 1 which will happen after the parent terminates. Then in the parent you:
wait;
which will wait for the child to terminate. So you have the child waiting for the parent to terminate and the parent waiting for the child to terminate thus they are both stuck. Normally when you fork you don't wait for your parent to be init so i would get rid of the sleep until line, also the example you provided might just as well be written without a fork since the parent does nothing other than wait for the child to finish its job the parent could just as well have done that job instead.