isProcessRunning

Check whether a process is currently running.

Overload accepting a std.process.Pid directly.

  1. bool isProcessRunning(int pid)
  2. bool isProcessRunning(Pid pid)
    @trusted nothrow
    bool
    isProcessRunning
    (
    Pid pid
    )

Parameters

pid Pid

Pid handle returned by spawnProcess or similar.

Return Value

Type: bool

true if the process appears to be running, false otherwise.

Examples

isProcessRunning returns true for a live process and false after it exits

import unit_threaded.assertions;
import std.process : spawnProcess, kill, wait;

version(Posix) {
    auto pid = spawnProcess(["sleep", "10"]);
} else version(Windows) {
    auto pid = spawnProcess(["cmd", "/c", "timeout", "/t", "10", "/nobreak"]);
}
int rawPid = pid.processID;

isProcessRunning(rawPid).shouldBeTrue;
isProcessRunning(pid).shouldBeTrue;

pid.kill();
pid.wait();

isProcessRunning(rawPid).shouldBeFalse;
isProcessRunning(pid).shouldBeFalse;

Meta