View source code Display the source code in std/process.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.process.wait

Waits for the process associated with pid to terminate, and returns its exit status.

In general one should always wait for child processes to terminate before exiting the parent process. Otherwise, they may become "zombies" – processes that are defunct, yet still occupy a slot in the OS process table.

If the process has already terminated, this function returns directly. The exit code is cached, so that if wait() is called multiple times on the same Pid it will always return the same value.

Prototype

int wait(
  Pid pid
) @safe;

POSIX specific

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 core.sys.posix.signal module (which corresponds to the signal.h POSIX header).

Throws

ProcessException on failure.

Examples

See the spawnProcess documentation.

See also

tryWait, for a non-blocking function.

Authors

Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev

License

Boost License 1.0.

Comments