Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm not sure what reap_children is supposed to do. What it does is reap any dead children. Your args to waitpid say "Check to see if any processes are dead, but don't hang this process waiting." You also don't seem to be doing anything with $kid since if more than one process dies, you ignore the pid of the first one. Follow maverick's advice if you care when they are all dead. If you are just trying to avoid zombies, do  $SIG{CHLD} = sub {wait}; It really depends on what you want to do.

Now, why does your process appear to wait for some children to die? Well, one possibility is that you have exceeded the maximum number of children your OS allows. That is, if you have a lot of files to process, you may have forked as many children as you are allowed to fork. To figure that out you can keep track of the number of live children and see if that number gets big. The limit on my system is 511.

BTW you can avoid the magic numbers in waitpid if you use POSIX "sys_wait_h";.

HTH, --traveler

Update: I'd never heard about the 2% chance of corruption. I've always followed the Camel's advice about using the signal handler, I guess I've been lucky. Maybe one choice is to do a periodic wait for children using code similar to reap_children. You might also try setting $SIG{CHLD} to SIG_IGN.


In reply to Re: fork()ing a large process by traveler
in thread fork()ing a large process by Jonathan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-23 21:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found