wait
| Number | 0x03 |
|---|---|
| Signature | (pid, &status, flags) -> pid or -err |
| Group | task |
| Since | 1.0 |
| Blocking | conditional |
Wait for a child to exit and reap it, reading back its exit status.
With a specific PID, waits on that child. With -1, waits on any child. Without WNOHANG
the call blocks until a matching child exits; with WNOHANG it returns 0 immediately if
none has. On success the child is reaped and its PID returned.
The status word carries how the child died:
- A clean exit holds whatever value the child passed to
pquit. - A killed child holds
KILLED_TAG | reason. Decode withWAS_KILLED(status)andKILL_REASON(status):KILL_BY_PARENTforpkill, theKILL_FAULT_*family for a fault,KILL_OOMfor an out-of-memory kill.
Pitfalls
A child that exits but is never waited on stays a zombie until reaped. A parent that spawns
and kills children without ever calling wait leaks them; a long-lived supervisor must
reap. If the parent dies first, its zombies reparent to pid 1, which reaps them.
Arguments
| Register | Name | Description |
|---|---|---|
r0 | pid | PID of the child to wait on, or -1 for any child |
r1 | &status | Pointer the kernel fills with the child's exit status. May be null? — confirm |
r2 | flags | `WNOHANG` to return immediately if no child has exited |
Returns
The PID of the reaped child, or 0 if WNOHANG and none had exited.
Errors
| Code | Condition |
|---|---|
ERR_BADARG | PID is negative and not -1 |
ERR_NOENT | No matching child exists, or none became reapable |
ERR_BADPTR | Status pointer is invalid |