Hello, I'm having some trouble understanding how fork() really works on ActiveState's Perl implementation. I would like to fork() a method multiple times that uses values derived from a data structure (like an array)..but I can't quite figure out how to wrap this (example below) code fragment into a foreach{} (or some such) that will track the completeness of the multiple pids.
I am using the example code found in question #714300. Here it is..
use POSIX":sys_wait_h"; my $pid = fork(); my $check; die "can't fork:$?" unless(defined $pid); if ($pid != 0) { print "I am the parent\n"; my $flag = 0; while ($flag == 0) { $check = waitpid($pid,&WNOHANG); print "Waitpid returned $check\n"; if ($check != 0) { print "Parent caught death of child $pid\n"; $flag = 1; } else { sleep 1; print "Not yet caught\n"; } } print "Parent is exiting\n"; } else { print "I am the child\n"; sleep 3; print "Child is exiting\n"; exit (0); }
In reply to tracking multiple waitpid(s) by wxfield
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |