8.7. waitid Function
The XSI extension of the Single UNIX Specification includes an additional function to retrieve the exit status of a process. The waitid function is similar to waitpid, but provides extra flexibility.
#include <sys/wait.h>
int waitid(idtype_t idtype, id_t id, siginfo_t
*infop, int options);
| Returns: 0 if OK, 1 on error |
Like waitpid, waitid allows a process to specify which children to wait for. Instead of encoding this information in a single argument combined with the process ID or process group ID, two separate arguments are used. The id parameter is interpreted based on the value of idtype. The types supported are summarized in Figure 8.9.
Figure 8.9. The idtype constants for waitidConstant | Description |
---|
P_PID | Wait for a particular process: id contains the process ID of the child to wait for. | P_PGID | Wait for any child process in a particular process group: id contains the process group ID of the children to wait for. | P_ALL | Wait for any child process: id is ignored. |
The options argument is a bitwise OR of the flags shown in Figure 8.10. These flags indicate which state changes the caller is interested in.
Figure 8.10. The options constants for waitidConstant | Description |
---|
WCONTINUED | Wait for a process that has previously stopped and has been continued, and whose status has not yet been reported. | WEXITED | Wait for processes that have exited. | WNOHANG | Return immediately instead of blocking if there is no child exit status available. | WNOWAIT | Don't destroy the child exit status. The child's exit status can be retrieved by a subsequent call to wait, waitid,or waitpid. | WSTOPPED | Wait for a process that has stopped and whose status has not yet been reported. |
The infop argument is a pointer to a siginfo structure. This structure contains detailed information about the signal generated that caused the state change in the child process. The siginfo structure is discussed further in Section 10.14.
Of the four platforms covered in this book, only Solaris provides support for waitid.
|