mirror of
https://github.com/ziglang/zig.git
synced 2025-02-10 22:50:18 +00:00
std: add ChildProcess.kill
This commit is contained in:
parent
7e59f4ff69
commit
9f7e62b95b
@ -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 {
|
||||
|
@ -6,4 +6,5 @@ pub fn build(b: &Builder) {
|
||||
exe.setBuildMode(mode);
|
||||
|
||||
b.default_step.dependOn(&exe.step);
|
||||
b.installArtifact(exe);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user