Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a parent process that forks off some child processes. Because the child processes take a while to finish, the parent process would like to do other things while waiting for them to finish. What is the syntax for this? Far as I can tell, wait() just waits forever.

Replies are listed 'Best First'.
Re: how to do things while waiting?
by LD2 (Curate) on May 16, 2001 at 06:09 UTC
Re (tilly) 1: how to do things while waiting?
by tilly (Archbishop) on May 16, 2001 at 15:59 UTC
    Look up waitpid. Alternately you might want to try:
    $SIG{CHLD} = 'IGNORE';
    and not worry about your kids. (On most Unix platforms I believe this will cause them to be auto-reaped without using Perl's unreliable signals.)

      No, that only works on SVR4-based versions of Unix and not on BSD-based versions of Unix. (Now that Sun has converted to SVR4-based, you might be able to argue "most" is appropriate, but I won't.)

              - tye (but my friends call me "Tye")
        Quoting from perlipc for version 5.005_03:
        On most UNIX platforms, the CHLD (sometimes also known as CLD) signal has special behavior with respect to a value of 'IGNORE'. Setting $SIG{CHLD} to 'IGNORE' on such a platform has the effect of not creating zombie processes when the parent process fails to wait() on its child processes (i.e. child processes are automatically reaped). Calling wait() with $SIG{CHLD} set to 'IGNORE' usually returns -1 on such platforms.
        So if you don't like my wording, you should check whether it is still needed and then send in a documentation patch.