Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Managing the fork/execing and reaping of child processes

by Anonymous Monk
on Jul 16, 2015 at 18:10 UTC ( [id://1135061]=note: print w/replies, xml ) Need Help??


in reply to Re: Managing the fork/execing and reaping of child processes
in thread Managing the fork/execing and reaping of child processes

Rendered readable:
#!/usr/bin/perl # http://perlmonks.org/?node_id=1135034 use strict; $| = 1; my $active_readers = 0; my $current_reader_limit = 10; my $total = 0; while(1) { if($active_readers < $current_reader_limit) { $active_readers++; ++$total; if(my $pid = fork) { # parent print "Spawned child $active_readers pid $pid total $tota +l\n"; } elsif(defined $pid) { # child exec "echo Hello from child $active_readers pid \$\$" or die "exec failed with $!"; } else { # fork failed die "fork failed with $!"; } } elsif((my $pid = wait()) > 0) { $active_readers--; print "Reaped $pid, active = $active_readers\n" } }

Replies are listed 'Best First'.
Re^3: Managing the fork/execing and reaping of child processes
by Anonymous Monk on Jul 16, 2015 at 19:31 UTC
    Sigh...

Log In?
Username:
Password:

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

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

    No recent polls found