isProcessAlive function

bool isProcessAlive(
  1. int pid
)

Whether pid currently refers to a live process on this host.

Use this for PIDs read from disk (pidfiles, supervisor records, foreign subtree members). For subprocesses you spawned, prefer holding the Process instance and awaiting Process.exitCode - no PID-recycling race, reactive on exit.

POSIX: kill(pid, 0) (non-delivering probe). EPERM (cross-user PID recycling) is reported as dead - a non-issue on a single-user dev box.

Windows: OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, ...) returns a handle iff the PID is assigned, with no ACL grant required.

Implementation

bool isProcessAlive(int pid) {
  if (Platform.isWindows) {
    return _withProcessHandle(pid, (_) => true) ?? false;
  }
  return _libcKill(pid, 0) == 0;
}