Domanda

Is the return value from Perl's system() call always the exact same value as $? will be immediately after the same call?

Are there any kernel/shell/system failure modes in which this will not be the case, such as system even failing to start a sub-shell?

(I'm not asking about the encoding of the bits, with the return code (in the high bits), signals, and core dump flag.)

È stato utile?

Soluzione

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 Unix wait() 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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top