Function std.process.tryWait
A non-blocking version of wait
.
If the process associated with
has already terminated,
pid
has the exact same effect as tryWait
.
In this case, it returns a tuple where the wait
terminated
field
is set to true
and the status
field has the same
interpretation as the return value of
.
wait
If the process has not yet terminated, this function differs
from
in that does not wait
wait
for this to happen, but instead
returns immediately. The terminated
field of the returned
tuple will then be set to false
, while the status
field
will always be 0 (zero).
or wait
should then be
called again on the same tryWait
at some later time; not only to
get the exit code, but also to avoid the process becoming a "zombie"
when it finally terminates. (See Pid
wait
for details).
Prototype
auto Tuple!(bool,"terminated",int,"status") tryWait( Pid pid ) @safe;
Returns
An
.
std.typecons.Tuple
!(bool, "terminated", int, "status")
Throws
ProcessException
on failure.
Example
auto pid = spawnProcess("dmd myapp.d"); scope(exit) wait(pid); ... auto dmd = tryWait(pid); if (dmd.terminated) { if (dmd.status == 0) writeln("Compilation succeeded!"); else writeln("Compilation failed"); } else writeln("Still compiling..."); ...
Note that in this example, the first
call will have no
effect if the process has already terminated by the time wait
is called. In the opposite case, however, the tryWait
scope
statement
ensures that we always wait
for the process if it hasn't terminated
by the time we reach the end of the scope.
Authors
Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev