waitpid should specify WNOHANG

If the child process our terminal is executing behaves poorly and
doesn't waitpid all of its own children, then we can hang the full
terminal. This is not ideal, so specify WNOHANG.
This commit is contained in:
Mitchell Hashimoto
2022-11-16 20:54:17 -08:00
parent 56b5c81fcb
commit d567a976b4

View File

@ -186,7 +186,10 @@ fn setupFd(src: File.Handle, target: i32) !void {
/// Wait for the command to exit and return information about how it exited. /// Wait for the command to exit and return information about how it exited.
pub fn wait(self: Command) !Exit { pub fn wait(self: Command) !Exit {
const res = std.os.waitpid(self.pid.?, 0); // We specify NOHANG because its not our fault if the process we launch
// for the tty doesn't properly waitpid its children. We don't want
// to hang the terminal over it.
const res = std.os.waitpid(self.pid.?, std.c.W.NOHANG);
return Exit.init(res.status); return Exit.init(res.status);
} }