summaryrefslogtreecommitdiff
path: root/js/process.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-04-21 18:26:56 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-04-21 21:26:56 -0400
commit1d4b92ac85d8c850270ca859f928404c72c0a49a (patch)
tree2f45ea65a3a3c5879fe7b16cacfd5624d86764cd /js/process.ts
parent9dfebbc9496138efbeedc431068f41662c780f3e (diff)
Add Deno.kill(pid, signo) and process.kill(signo) (Unix only) (#2177)
Diffstat (limited to 'js/process.ts')
-rw-r--r--js/process.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/js/process.ts b/js/process.ts
index a0eef63dd..c0a66f311 100644
--- a/js/process.ts
+++ b/js/process.ts
@@ -7,6 +7,7 @@ import { File, close } from "./files";
import { ReadCloser, WriteCloser } from "./io";
import { readAll } from "./buffer";
import { assert, unreachable } from "./util";
+import { platform } from "./build";
/** How to handle subprocess stdio.
*
@@ -51,6 +52,16 @@ async function runStatus(rid: number): Promise<ProcessStatus> {
}
}
+/** Send a signal to process under given PID. Unix only at this moment.
+ * If pid is negative, the signal will be sent to the process group identified
+ * by -pid.
+ */
+export function kill(pid: number, signo: number): void {
+ const builder = flatbuffers.createBuilder();
+ const inner = msg.Kill.createKill(builder, pid, signo);
+ dispatch.sendSync(builder, msg.Any.Kill, inner);
+}
+
export class Process {
readonly rid: number;
readonly pid: number;
@@ -113,6 +124,10 @@ export class Process {
close(): void {
close(this.rid);
}
+
+ kill(signo: number): void {
+ kill(this.pid, signo);
+ }
}
export interface ProcessStatus {
@@ -179,3 +194,77 @@ export function run(opt: RunOptions): Process {
return new Process(res);
}
+
+// From `kill -l`
+enum LinuxSignal {
+ SIGHUP = 1,
+ SIGINT = 2,
+ SIGQUIT = 3,
+ SIGILL = 4,
+ SIGTRAP = 5,
+ SIGABRT = 6,
+ SIGBUS = 7,
+ SIGFPE = 8,
+ SIGKILL = 9,
+ SIGUSR1 = 10,
+ SIGSEGV = 11,
+ SIGUSR2 = 12,
+ SIGPIPE = 13,
+ SIGALRM = 14,
+ SIGTERM = 15,
+ SIGSTKFLT = 16,
+ SIGCHLD = 17,
+ SIGCONT = 18,
+ SIGSTOP = 19,
+ SIGTSTP = 20,
+ SIGTTIN = 21,
+ SIGTTOU = 22,
+ SIGURG = 23,
+ SIGXCPU = 24,
+ SIGXFSZ = 25,
+ SIGVTALRM = 26,
+ SIGPROF = 27,
+ SIGWINCH = 28,
+ SIGIO = 29,
+ SIGPWR = 30,
+ SIGSYS = 31
+}
+
+// From `kill -l`
+enum MacOSSignal {
+ SIGHUP = 1,
+ SIGINT = 2,
+ SIGQUIT = 3,
+ SIGILL = 4,
+ SIGTRAP = 5,
+ SIGABRT = 6,
+ SIGEMT = 7,
+ SIGFPE = 8,
+ SIGKILL = 9,
+ SIGBUS = 10,
+ SIGSEGV = 11,
+ SIGSYS = 12,
+ SIGPIPE = 13,
+ SIGALRM = 14,
+ SIGTERM = 15,
+ SIGURG = 16,
+ SIGSTOP = 17,
+ SIGTSTP = 18,
+ SIGCONT = 19,
+ SIGCHLD = 20,
+ SIGTTIN = 21,
+ SIGTTOU = 22,
+ SIGIO = 23,
+ SIGXCPU = 24,
+ SIGXFSZ = 25,
+ SIGVTALRM = 26,
+ SIGPROF = 27,
+ SIGWINCH = 28,
+ SIGINFO = 29,
+ SIGUSR1 = 30,
+ SIGUSR2 = 31
+}
+
+/** Signals numbers. This is platform dependent.
+ */
+export const Signal = platform.os === "mac" ? MacOSSignal : LinuxSignal;