authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-06 18:30:45-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-06 18:30:45-04:00
log9f7e62b95bf36b7a867ffcee576c929e9564c303
tree562a488aaae1a1fbeee8af5f3b6377118f163f3b
parent7e59f4ff69f9a8634c4e8d49cea95a3b55dbe771

std: add ChildProcess.kill


2 files changed, 19 insertions(+), 0 deletions(-)

std/os/child_process.zig+18
...@@ -9,6 +9,9 @@ const BufMap = @import("../buf_map.zig").BufMap;...@@ -9,6 +9,9 @@ const BufMap = @import("../buf_map.zig").BufMap;
9const builtin = @import("builtin");9const builtin = @import("builtin");
10const Os = builtin.Os;10const Os = builtin.Os;
1111
12error PermissionDenied;
13error ProcessNotFound;
14
12pub const ChildProcess = struct {15pub const ChildProcess = struct {
13 pid: i32,16 pid: i32,
14 err_pipe: [2]i32,17 err_pipe: [2]i32,
...@@ -43,6 +46,21 @@ pub const ChildProcess = struct {...@@ -43,6 +46,21 @@ pub const ChildProcess = struct {
43 }46 }
44 }47 }
4548
49 /// Forcibly terminates child process and then cleans up all resources.
50 pub fn kill(self: &ChildProcess) -> %Term {
51 const ret = posix.kill(self.pid, posix.SIGTERM);
52 const err = posix.getErrno(ret);
53 if (err > 0) {
54 return switch (err) {
55 posix.EINVAL => unreachable,
56 posix.EPERM => error.PermissionDenied,
57 posix.ESRCH => error.ProcessNotFound,
58 else => error.Unexpected,
59 };
60 }
61 return self.wait();
62 }
63
46 /// Blocks until child process terminates and then cleans up all resources.64 /// Blocks until child process terminates and then cleans up all resources.
47 pub fn wait(self: &ChildProcess) -> %Term {65 pub fn wait(self: &ChildProcess) -> %Term {
48 defer {66 defer {
std/special/build_file_template.zig+1
...@@ -6,4 +6,5 @@ pub fn build(b: &Builder) {...@@ -6,4 +6,5 @@ pub fn build(b: &Builder) {
6 exe.setBuildMode(mode);6 exe.setBuildMode(mode);
77
8 b.default_step.dependOn(&exe.step);8 b.default_step.dependOn(&exe.step);
9 b.installArtifact(exe);
9}10}