Only one byte is allowed for a return status on UNIX, so 255, 0xff, all bits set is the max allowed. Setting 256 potentially sets a bit in the more significant byte, leaving the status byte as zero. | [reply] |
Thanks for the information. So does 256 exit status means a successful exit of the child process? What happened is there is a bug in one of our program and the program will abort if $? >> 8 == 0. I can see if I terminate a child process, the exit status of wait is 0. But I thought the exit status of 0 means success, that's why I am a little bit confused.
| [reply] |
So does 256 exit status means a successful exit of the child process? No, you cannot exit with 256 from UNIX, only 0-255. However, if you are talking about $?, that is a different matter. As others have said, $? contains many things other than just the return code. If the child process terminated because of a signal then the signal number is in $? as well.
$exit_value = $? >> 8;
$signal_num = $? & 127;
$dumped_core = $? & 128;
I think there has been some confusion over what you mean by an exit value.
| [reply] [d/l] |
According to the Camel Book, this function waits for a child process to terminate. $? contains the pid of the deceased process, or -1 if there are no child processes.
Revised: Please ignore.
| [reply] |
| [reply] |
I think it's rather (citing "perldoc -f wait"):
...it waits for a child process to terminate and returns the pid of the
deceased process, or "-1" if there are no child processes. The status
is returned in $?.
See man 2 wait on how to interpret the return status. Also,
perldoc -f system has some sample code for properly handling $?.
| [reply] [d/l] [select] |
wait() return the pid, but $? returns the return status. For example:
$a = wait();
$a is the pid and $? is the return status.
| [reply] |