in reply to dbi and fork

Another way is to have each child monitor the parent:

$ppid = getppid;

and then terminate when the parent does:

while (getppid == $ppid) { # process until parent dies }

If the code and the comments disagree, then both are probably wrong. -- Norm Schryer