Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: fork()ing a large process

by dws (Chancellor)
on Nov 29, 2001 at 22:20 UTC ( [id://128425]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://128425]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-16 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found