[cs631apue] sish return code question

Jan Schaumann jschauma at stevens.edu
Thu Dec 5 22:01:34 EST 2019


David Sevilla <dsevilla at stevens.edu> wrote:

> The manual page states that a "status of 127 should be returned if the
> given command could not be executed for any reason." I interpreted "could
> not be executed" as "could not begin executing".

It really is 'the call to exec returned'.  If exec
does not return, then the status of the command will
be whatever wait(3) tells you it is.  Something like
this pseudo-code:

fork
child:
    exec(...)
    /* if we ever get here, exec failed, so return 127 */
parent:
    wait for child
    get exit status from child
 
> My Findings:
> Apparently it's required by POSIX for the exit code for processes which
> were terminated by a signal is greater than 128.

Where did you find that?  I'm looking at
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html,
which does not specify this.  (Some shells do indeed
implement this and make note of this in their manual
pages, but I don't think that's required by POSIX.)

> Is it correct and expected that I should handle
> termination by a signal as a special case?

You do not need to handle this.  The above pseudo code
is sufficient.

-Jan


More information about the cs631apue mailing list