Skip to content
Advertisement

C wait3() int* status or int* stat_loc

I indeed to use wait3(). I have been looking what exactly is status/stat_loc but I couldn’t find it anywhere.

Any explanation is greatly appreciated!

Advertisement

Answer

man wait explains the semantics of status:

   If status is not NULL, wait() and waitpid() store status information in
   the  int  to  which  it points.  This integer can be inspected with the
   following macros (which take the integer itself as an argument,  not  a
   pointer to it, as is done in wait() and waitpid()!):

   WIFEXITED(status)
          returns true if the child terminated normally, that is, by call‐
          ing exit(3) or _exit(2), or by returning from main().

   WEXITSTATUS(status)
          returns the exit status of the  child.   This  consists  of  the
          least  significant  8 bits of the status argument that the child
          specified in a call to exit(3) or _exit(2) or  as  the  argument
          for  a  return  statement  in main().  This macro should only be
          employed if WIFEXITED returned true.

   WIFSIGNALED(status)
          returns true if the child process was terminated by a signal.

   WTERMSIG(status)
          returns the number of the signal that caused the  child  process
          to terminate.  This macro should only be employed if WIFSIGNALED
          returned true.

   WCOREDUMP(status)
          returns true if the child produced  a  core  dump.   This  macro
          should  only  be  employed  if  WIFSIGNALED returned true.  This
          macro is not specified in POSIX.1-2001 and is not  available  on
          some  Unix  implementations  (e.g.,  AIX, SunOS).  Only use this
          enclosed in #ifdef WCOREDUMP ... #endif.

   WIFSTOPPED(status)
          returns true if the child process was stopped by delivery  of  a
          signal;  this  is  only possible if the call was done using WUN‐
          TRACED 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 should only be employed if WIFSTOPPED returned true.

   WIFCONTINUED(status)
          (since  Linux  2.6.10)  returns  true  if  the child process was
          resumed by delivery of SIGCONT.
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement