lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Aaron Brown wrote:
[...]
and is right as usual.  The following program (compiled with
gcc on Linux) prints "system returned: 10752":

system() is implemented using wait(). There are a bunch of macros available for pulling out useful info from the return code for wait(). 'man wait' will give the list:

       WIFEXITED(status)
              returns true if the child terminated normally, that
              is,  by  calling exit() or _exit(), or by returning
              from main().

       WEXITSTATUS(status)
              evaluates to the least significant  eight  bits  of
              the  return  code  of  the  child which terminated,
              which may have been set as the argument to  a  call
              to  exit()  or  _exit()  or  as  the argument for a
              return statement in the main program.   This  macro
              can only be evaluated if WIFEXITED returned true.

       WIFSIGNALED(status)
              returns   true  if  the  child  process  terminated
              because of a signal which was not caught.

       WTERMSIG(status)
              returns the number of the signal  that  caused  the
              child  process to terminate. This macro can only be
              evaluated if WIFSIGNALED returned non-zero.

       WIFSTOPPED(status)
              returns true if the child process which caused  the
              return  is currently stopped; this is only possible
              if the call was done using WUNTRACED  or  when  the
              child is being traced (see ptrace(2)).

       WSTOPSIG(status)
              returns  the  number of the signal which caused the
              child to stop.  This macro can only be evaluated if
              WIFSTOPPED returned non-zero.

I think these are Posix; does anyone have a Posix reference anywhere?

--
[insert interesting .sig here]