Waits for the process associated with
pid to terminate, and returns
its exit status.
int wait (
In general one should always wait for child processes to terminate
before exiting the parent process unless the process was spawned as detached
(that was spawned with
Otherwise, they may become "zombies"
– processes that are defunct, yet still occupy a slot in the OS process table.
You should not and must not wait for detached processes, since you don't own them.
If the process has already terminated, this function returns directly.
The exit code is cached, so that if wait() is called multiple times on
Pid it will always return the same value.
If the process is terminated by a signal, this function returns a
negative number whose absolute value is the signal number.
Since POSIX restricts normal exit codes to the range 0-255, a
negative return value will always indicate termination by signal.
Signal codes are defined in the
(which corresponds to the
signal POSIX header).
ProcessException on failure or on attempt to wait for detached process.
tryWait, for a non-blocking function.
Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev