Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Daemonized with max processes

by Marcello (Hermit)
on Aug 15, 2003 at 09:38 UTC ( #284108=note: print w/replies, xml ) Need Help??


in reply to Daemonized with max processes

Hi,

You should use a reaper, the following snippets should get you started:
use POSIX; use constant MAX_CHILDS => 6; my $CHILD_COUNT = 0; $SIG{CHLD} = \&Reaper; sub Reaper { my $childPid; while (($childPid = waitpid(-1, &WNOHANG)) > 0) { $CHILD_COUNT--; } $SIG{CHLD} = \&Reaper; } if ($CHILD_COUNT < MAX_CHILDS) { my $pid; if (!defined($pid = fork())) { # Fork failed } # Child process elsif ($pid == 0) { # Process file } # Parent process else { $CHILD_COUNT++; } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-06-02 18:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (19 votes). Check out past polls.

    Notices?