| ... | ... | @@ -9,6 +9,9 @@ const BufMap = @import("../buf_map.zig").BufMap; |
| 9 | 9 | const builtin = @import("builtin"); |
| 10 | 10 | const Os = builtin.Os; |
| 11 | 11 | |
| 12 | error PermissionDenied; |
| 13 | error ProcessNotFound; |
| 14 | |
| 12 | 15 | pub const ChildProcess = struct { |
| 13 | 16 | pid: i32, |
| 14 | 17 | err_pipe: [2]i32, |
| ... | ... | @@ -43,6 +46,21 @@ pub const ChildProcess = struct { |
| 43 | 46 | } |
| 44 | 47 | } |
| 45 | 48 | |
| 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 | 64 | /// Blocks until child process terminates and then cleans up all resources. |
| 47 | 65 | pub fn wait(self: &ChildProcess) -> %Term { |
| 48 | 66 | defer { |