in reply to Detect Process End

You've got good advice above, here are a couple more possibilities.

You can set up a $SIG{CHLD} handler to respond to a child process's exit, whatever the reason for it. If it's ok to sleep for a bit after some processing, waitpid will do that.

After Compline,
Zaxo