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...