i'm having trouble getting exit status of child processes. reason kill 0, $pid way doesn't seem work. i'm running following script on unix machine:
for ( $count = 1; $count <= 2; $count++) { $pid = fork(); if ($pid) { # parent push(@childs, $pid); } elsif ($pid == 0) { # child sleep(10); exit 0; } else { die "couldnt fork: $!\n"; }
}
foreach (@childs) { if (kill 0, $_){ print "$_ running...\n"; } else { print "$_ complete\n"; }
}
sleep (20); foreach (@childs) { if (kill 0, $_){ print "$_ running...\n"; } else { print "$_ complete\n"; }
}
the prints are:
23285 running...
23286 running...
23285 running...
23286 running...
can please explain why won't work, , maybe suggest solution or workaround ?
many thanks!
whenever need fork 1 child , wait use wait() function.
when have fork multiple children , wait them, use parallel::forkmanager module.
Comments
Post a Comment