in reply to How to fork one and only one child process from a loop ?

To handle the bit about checking whether an existing child process is still running, you'd want to use the waitpid function -- that is, if your system is one that supports the POSIX "WNO_HANG" flag for doing a non-blocking check as to whether a child process is still running.

In that case, once waitpid returns a status value that indicates the child process is finished, you can reset the $kidpid value to zero, so that your loop can launch another child if it wants to.

  • Comment on Re: How to fork one and only one child process from a loop ?