in reply to fork()ing a large process

I have a process that polls for files and forks a child process to handle each file as it arrives. The problem is that sometimes it waits for the child to exit before moving on to the next. This seems to happen when processing the larger files.

For the proper way to reap children, consult perlman:perlipc. The section on "Signals" is near the top of the document, and describes how to set up a SIGCHLD handler to correctly account for the death of a child process.

If you don't handle SIGCHLD correctly, you could be getting blocked on wait().

Replies are listed 'Best First'.
(tye)Re: fork()ing a large process
by tye (Sage) on Nov 29, 2001 at 22:34 UTC

    Actually, using a signal handler to reap children is problematic in Perl because Perl signal handlers aren't 100% reliable. Each time one is trigger, you have something like a 2% chance of corrupting Perl's internal structures. I think this may be fixed in a an upcoming version of Perl.

    The safest way to reap children is shown under "perldoc -f waitpid" and closely matches the code in question. Perhaps Solaris doesn't define WNOHANG as 1? That seems unlikely, but that is all I've come up with so far.

            - tye (but my friends call me "Tye")
      Thanks for looking at it tye. I hoped it might have been something to do with my Perl version. I'm stuck.