CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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