| 1 | /** |
| 2 | * Signals a POSIX process group this server spawned, as `process.kill(-pid)`. |
| 3 | * |
| 4 | * `kill(0)` signals this server's own group and `kill(-1)` every process the |
| 5 | * user owns, and a fake spawner in tests reports pid 1. So a pid of 0 or 1, or |
| 6 | * one that is not an integer, fails with ESRCH like a group that has already |
| 7 | * exited, and callers keep their existing handling. |
| 8 | */ |
| 9 | export function signalProcessGroup(pid: number, signal: NodeJS.Signals | 0): void { |
| 10 | if (!Number.isSafeInteger(pid) || pid <= 1) { |
| 11 | throw Object.assign(new Error(`kill ESRCH: not a spawned process group (${pid})`), { |
| 12 | code: "ESRCH", |
| 13 | }); |
| 14 | } |
| 15 | process.kill(-pid, signal); |
| 16 | } |