in reply to Re^3: forkManager PID 1 less than top
in thread forkManager PID 1 less than top
Where did you find the code example you posted?I edited first example (in SYNOPSIS) here.
I should have expected this since system probably starts it's own child process.Exactly!
or if the actual offset is subject to system timing?yep.
having said all that I am really not sure how to properly work around this.Why do you need exactly the PID which do the work?
i.e. use "exec", "fork" and "wait/waitpid" calls.use Parallel::ForkManager; $pm = new Parallel::ForkManager(100); my @all_data = qw/1/; foreach $data (@all_data) { # Forks and returns the pid for the child: my $pid = $pm->start; print "PID $pid\n"; $pid and next; print "$data", "\n"; my $pid2 = fork(); unless ($pid2) { exec $^X, '-e', 'while(){}'; } print "Real PID $pid2\n"; waitpid $pid2, 0; $pm->finish; # Terminates the child process } $pm->wait_all_children;
withexec $^X, '-e', 'while(){}';
those calls are equivalent, but former calls PERL, and later one calls SHELL, which will call PERL.exec "perl -e 'while(){}'";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: forkManager PID 1 less than top
by MAR99 (Initiate) on Oct 03, 2013 at 17:06 UTC | |
by vsespb (Chaplain) on Oct 03, 2013 at 17:32 UTC |