Function std.process.kill
Attempts to terminate the process associated with
.
pid
The effect of this function, as well as the meaning of
,
is highly platform dependent. Details are given below. Common to all
platforms is that this function only initiates termination of the process,
and returns immediately. It does not codeOrSignal
wait
for the process to end,
nor does it guarantee that the process does in fact get terminated.
Always call wait
to wait
for a process to complete, even if
has been called on it.
kill
Prototypes
void kill( Pid pid ); void kill( Pid pid, int codeOrSignal );
Windows specific
The process will be
forcefully and abruptly terminated. If
is specified, it
must be a nonnegative number which will be used as the exit code of the process.
If not, the process wil exit with code 1. Do not use codeOrSignal
,
as this is a special value (aka. STILL_ACTIVE)
used by Windows to signal that a process has in fact not terminated yet.
codeOrSignal
= 259
auto pid = spawnProcess("some_app"); kill(pid, 10); assert (wait(pid) == 10);
POSIX specific
A signal will be sent to
the process, whose value is given by
. Depending on the
signal sent, this may or may not terminate the process. Symbolic constants
for various
POSIX signals are defined in codeOrSignal
core.sys.posix.signal
, which corresponds to the
signal.h
POSIX header. If
is omitted, the
codeOrSignal
SIGTERM
signal will be sent. (This matches the behaviour of the
kill
shell
command.)
import core.sys.posix.signal: SIGKILL; auto pid = spawnProcess("some_app"); kill(pid, SIGKILL); assert (wait(pid) == -SIGKILL); // Negative return value on POSIX!
Throws
ProcessException
on error (e.g. if codeOrSignal
is invalid).
Note that failure to terminate the process is considered a "normal"
outcome, not an error.
Authors
Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev