Is the return value from Perl's system() call always the exact same value as $? will be immediately after the same call?
Yes, they both come from Unix system call wait()
.
According to system
:
The return value is the exit status of the program as returned by the
wait
call.
and perlvar
:
$?
This is just the 16-bit status word returned by the traditional Unixwait()
system call (or else is made up to look like it).
Note: according to the prototype of wait(2)
, which is pid_t wait(int *stat_loc)
, obviously, the return value of system
is NOT the return value of wait(2)
, which is a process id. It is the child process exit status returned by wait(2)
through its first parameter, because a C function can only return one value, if it wants to return more than one value, it needs to wrap them in a structure and return a value of that structure type, or through parameters of pointer type.