in reply to Re: Access value of a variable after exit 0 in fork
in thread Access value of a variable after exit 0 in fork

Can you please elaborate via some code? Sorry to give you trouble,but just want to understand thoroughly.
  • Comment on Re^2: Access value of a variable after exit 0 in fork

Replies are listed 'Best First'.
Re^3: Access value of a variable after exit 0 in fork
by Anonymous Monk on Dec 27, 2012 at 10:52 UTC
    See perlipc and waitpid
    if( my $pid = fork() ){ print "parent ($$) is waiting on child $pid\n"; my $kid ; do { $kid = waitpid(-1, WNOHANG); } while $kid > 0; my $exit = $? >> 8; die qq{Kid ($kid) exited with $? / $exit \n}; } else { print "I am the kid $$\n"; sleep 1; #~ exit 666; ## too big exit 12; } __END__ parent (1724) is waiting on child -880 I am the kid -880 Kid (-880) exited with 3072 / 12

    There are abstractions to help you manage this like Parallel::ForkManager, Proc::Fork, forks, threads ....