Path: blob/master/src/packages/backend/misc/process-kill.ts
1447 views
import getLogger from "@cocalc/backend/logger";1const logger = getLogger("process-kill");23// sends kill 2,3,9 signal to pid.4// never raises an exception.5export default function processKill(pid: number, signal: 2 | 3 | 9) {6let s;7switch (signal) {8case 2:9s = "SIGINT";10break;11case 3:12s = "SIGQUIT";13break;14case 9:15s = "SIGKILL";16break;17default:18logger.debug(19"WARNING -- process_kill: only signals 2 (SIGINT), 3 (SIGQUIT), and 9 (SIGKILL) are supported"20);21return;22}23try {24logger.debug("process.kill -- pid=", pid, " signal=", signal);25process.kill(pid, s);26} catch (_err) {}27}2829// it's normal to get an exception when sending a signal... to a process that doesn't exist.303132