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;
99const builtin = @import("builtin");
1010const Os = builtin.Os;
1111
12error PermissionDenied;
13error ProcessNotFound;
14
1215pub const ChildProcess = struct {
1316 pid: i32,
1417 err_pipe: [2]i32,
......@@ -43,6 +46,21 @@ pub const ChildProcess = struct {
4346 }
4447 }
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
4664 /// Blocks until child process terminates and then cleans up all resources.
4765 pub fn wait(self: &ChildProcess) -> %Term {
4866 defer {
std/special/build_file_template.zig+1
......@@ -6,4 +6,5 @@ pub fn build(b: &Builder) {
66 exe.setBuildMode(mode);
77
88 b.default_step.dependOn(&exe.step);
9 b.installArtifact(exe);
910}