There are two things wrong with that. If the fork fails, $pid is undef, but will still compare true to 0. Second, if it fails, the error is in $!, not $pid. So you actually want:my $pid=fork(); if ( $pid == 0 } { : child process goes here } elsif { $pid > 0 ) { : parent process wait(); # Wait for the child to exit } else { # WOAH! We should never get here! die "fork returned $pid"; }
my $pid=fork(); if (not defined $pid) { die "fork failed: $!\n"; } elsif ( $pid == 0 } { : child process goes here } else { : parent process wait(); # Wait for the child to exit }
Dave.
In reply to Re^2: quoted execution not working
by dave_the_m
in thread quoted execution not working
by gri6507
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |