sys_waitpid [kernel/exit.c]
Suspends execution of the current process until the specified child has changed state. A state change is considered to be: the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then terminated the child remains in a "zombie" state (see Remarks below). If a child has already changed state, then this call return immediately. Otherwise they block until either a child changes state or a signal handler interrupts the call (assuming that system calls are not automatically restarted using the SA_RESTART flag of sys_sigaction). Arguments
eax | 7
ebx | PID of the child. The value of PID can be:
`< -1` | `meaning wait for any child process whose process group ID is equal to the absolute value of ebx.`
`-1` | `meaning wait for any child process.`
`0` | `meaning wait for any child process whose process group ID is equal to that of the calling process.`
`> 0` | `meaning wait for the child whose process ID is equal to the value of ebx.`
ecx | Pointer to the buffer (4 bytes long) that will receive the bitmask indicating the cause of termination and other information about the terminated process. This argument can be 0. This value is constructed as follows: If the low-order 8 bits are equal to 0x7f, the child process has stopped. If the low-order 8 bits are non-zero and are not equal to 0x7f, the child process terminated due to a signal; the low-order 7 bits contain the number of the signal that terminated the process. In addition, if the low-order seventh bit (that is, bit 0x80) is set, a "core image" of the process was produced. Otherwise, the child process terminated due to a sys_exit call; the 8 bits higher up from the low-order 8 bits contain the low-order 8 bits of the argument that the child process passed to sys_exit.
edx | Option flags. It may be zero or a combination of the following flags (see Remarks!):
`WNOHANG` | `Return immediately if no child has exited.`
`WUNTRACED` | `Return if a child has stopped (but not traced via sys_ptrace). Status for traced children which have stopped is provided even if this option is not specified. This option is only effective if the SA_NOCLDSTOP flag has not been set for the SIGCHLD signal (see sys_sigaction).`
`WEXITED` | `Return if a child has exited.`
`WCONTINUED` | `(Since Linux 2.6.10) Return if a stopped child has been resumed by delivery of SIGCONT. This option is only effective if the SA_NOCLDSTOP flag has not been set for the SIGCHLD signal (see sys_sigaction).`
`WNOWAIT` | `*to be documented*`
Return values If the system call succeeds the return value is a PID of the child whose state has changed. If WNOHANG was specified and no child(ren) specified by ebx has yet changed state, then 0 is returned. If the system call fails the return value is one of the following errno values:
`-ECHILD` | `The process specified by ebx does not exist or is not a child of the calling process. (This can happen for one's own child if the action for SIGCHLD is set to SIG_IGN.)`
`-EINTR` | `WNOHANG was not set and an unblocked signal or a SIGCHLD was caught.`
`-EINVAL` | `edx argument was invalid.`
Remarks A child that terminates, but has not been waited for becomes a "zombie". The kernel maintains a minimal set of information about the zombie process (PID, termination status, resource usage information) in order to allow the parent to later perform a wait to obtain information about the child. As long as a zombie is not removed from the system via a wait, it will consume a slot in the kernel process table, and if this table fills, it will not be possible to create further processes. If a parent process terminates, then its "zombie" children (if any) are adopted by init (man 8 init), which automatically performs a wait to remove the zombies. If the disposition of SIGCHLD is set to SIG_IGN or the SA_NOCLDWAIT flag is set for SIGCHLD (see`sys_sigaction`), then children that terminate do not become zombies and a call to sys_wait4 or sys_waitpid will block until all children have terminated, and then fail with -ECHILD. In the Linux kernel, a kernel-scheduled thread is not a distinct construct from a process. Instead, a thread is simply a process that is created using the Linux-unique sys_clone system call; other routines such as the portable pthread_create (man 3 pthread_create) call are implemented using sys_clone. A thread can, and by default will, wait on children of other threads in the same thread group. The following options are for use with children created using sys_clone:
`__WCLONE` | `Wait for "clone" children only. If omitted then wait for "non-clone" children only. (A "clone" child is one which delivers no signal, or a signal other than SIGCHLD to its parent upon termination.) This option is ignored if __WALL is also specified.`
`__WALL` | `Wait for all children, regardless of type ("clone" or "non-clone").`
`__WNOTHREAD` | `Do not wait for children of other threads in the same thread group.`
See /samples/basic/waitpid.asm for an example. Compatibility n/a