diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-09-06 18:30:45 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-09-06 18:30:45 -0400 |
| commit | 9f7e62b95bf36b7a867ffcee576c929e9564c303 (patch) | |
| tree | 562a488aaae1a1fbeee8af5f3b6377118f163f3b /std | |
| parent | 7e59f4ff69f9a8634c4e8d49cea95a3b55dbe771 (diff) | |
| download | zig-9f7e62b95bf36b7a867ffcee576c929e9564c303.tar.gz zig-9f7e62b95bf36b7a867ffcee576c929e9564c303.zip | |
std: add ChildProcess.kill
Diffstat (limited to 'std')
| -rw-r--r-- | std/os/child_process.zig | 18 | ||||
| -rw-r--r-- | std/special/build_file_template.zig | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/std/os/child_process.zig b/std/os/child_process.zig index 88eaca9d52..149c3aca12 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -9,6 +9,9 @@ const BufMap = @import("../buf_map.zig").BufMap; const builtin = @import("builtin"); const Os = builtin.Os; +error PermissionDenied; +error ProcessNotFound; + pub const ChildProcess = struct { pid: i32, err_pipe: [2]i32, @@ -43,6 +46,21 @@ pub const ChildProcess = struct { } } + /// Forcibly terminates child process and then cleans up all resources. + pub fn kill(self: &ChildProcess) -> %Term { + const ret = posix.kill(self.pid, posix.SIGTERM); + const err = posix.getErrno(ret); + if (err > 0) { + return switch (err) { + posix.EINVAL => unreachable, + posix.EPERM => error.PermissionDenied, + posix.ESRCH => error.ProcessNotFound, + else => error.Unexpected, + }; + } + return self.wait(); + } + /// Blocks until child process terminates and then cleans up all resources. pub fn wait(self: &ChildProcess) -> %Term { defer { diff --git a/std/special/build_file_template.zig b/std/special/build_file_template.zig index db560c1c05..a3dfbc0c2c 100644 --- a/std/special/build_file_template.zig +++ b/std/special/build_file_template.zig @@ -6,4 +6,5 @@ pub fn build(b: &Builder) { exe.setBuildMode(mode); b.default_step.dependOn(&exe.step); + b.installArtifact(exe); } |
