Elie De Brauwer wrote: > Hello list, Hello,
> I recently encountered a small oddity. Suppose I have a process A: > > #!/usr/bin/perl > > use strict; > > print "Hello \n"; > sleep 1; > print "Goodbye\n"; > exit 9; > > Simply shows some out and gives a certain exit code. A second process, > simply calls fork, execs the child in a process and waits for the child > in the other process. In Perl this can look like this: > > my $cmd = "/home/user/proces.pl"; > my $pid = fork(); > if($pid == 0){ > print "Hi I'm a child\n"; > exec $cmd or die "Failed to run $cmd\n"; > }else{ > print "Hi I'm a parent waiting for child with PID: $pid\n"; > my $ret = waitpid($pid,0); > print "$pid exited with code ". ($?>>8) ."\n"; > } > > The oddity i located in the last line. It seemd that I had to divide $? > by 256 (or shift over 8 positions to the right) to get the correct exit > code. So my question is: > a) Is there an other way to wait for a child to die and get the exit code > b) Can someone explain the odd behaviour of the exit code ? Have you read the perl documentation on the functions and variables you are using? perldoc perlipc perldoc perlvar perldoc -f fork perldoc -f exec perldoc -f waitpid John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>