Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: fork()ing a large process

by Dogma (Pilgrim)
on Nov 30, 2001 at 14:17 UTC ( [id://128586]=note: print w/replies, xml ) Need Help??


in reply to fork()ing a large process

If you really don't care about the process returning just set $SIG{CHLD} = 'IGNORE' and ignore the issue of reaping all together. The other option is to do a NON blocking call to waitpid.
use POSIX qw(:sys_wait_h); sub REAPER { while ((my $pid = waitpid(-1,WNOHANG)) > 0) { # do something with $pid; } $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER;
Then you don't have to worry about your code blocking while waiting for children to return. However this doesn't mean you should do something like.
sub fork_bomb { while (1){ fork_a_kid(); } }
Speaking as a system administrator this won't earn you alot of good sysadmin karma. It is ok to fork many children just remember to limit the number of children on the system at any one time. Please read perlipc and perlfork they helped me out big time.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-04-23 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found