F
friend.05
My script is using fork so there are child processes. Sometimes my
script runs properly and output is correct. But sometime my script
gets stuck just after exiting child process.
Below is psudo code. (not sure if this helps, it is juist snap shot)
foreach my $w (keys %worklist) {
my $child;
unless ($child = fork()) {
die("connot for: $!") unless defined $child;
foreach my $file (@{$worklist{$w}}) {
#reading files processing of data and
creating hash tables.
}
#ouput files from hash tables. outfile files will be
for each child.
print "Worker $w $$ exiting\n";
#child
exiting
(#it gets stuck after printing this statement)
exit;
}
push(@workers, $child); #array of child PID
}
#wating for each child to finish.
foreach my $pid (@workers) {
$s = waitpid($pid, 0);
print "$s finished\n";
}
The freeze happens sometimes.
And I check the trace(truss -p on sun). I found that sometimes one of
the child goes to sleeping and parent is still waiting for that child
exit status. But it never gets that bcoz child is sleeping.
And suggestion what can be problem or else how can I debug more.
Thanks
script runs properly and output is correct. But sometime my script
gets stuck just after exiting child process.
Below is psudo code. (not sure if this helps, it is juist snap shot)
foreach my $w (keys %worklist) {
my $child;
unless ($child = fork()) {
die("connot for: $!") unless defined $child;
foreach my $file (@{$worklist{$w}}) {
#reading files processing of data and
creating hash tables.
}
#ouput files from hash tables. outfile files will be
for each child.
print "Worker $w $$ exiting\n";
#child
exiting
(#it gets stuck after printing this statement)
exit;
}
push(@workers, $child); #array of child PID
}
#wating for each child to finish.
foreach my $pid (@workers) {
$s = waitpid($pid, 0);
print "$s finished\n";
}
The freeze happens sometimes.
And I check the trace(truss -p on sun). I found that sometimes one of
the child goes to sleeping and parent is still waiting for that child
exit status. But it never gets that bcoz child is sleeping.
And suggestion what can be problem or else how can I debug more.
Thanks