Closed oconnor663 closed 7 years ago
This is going to run into an issue with then
. If there's a worker thread sitting on wait
on the child process, there's no way to kill
it, because both methods require &mut self
. r/rust question: https://www.reddit.com/r/rust/comments/5lk1lw/hey_rustaceans_got_an_easy_question_ask_here_12017/dc3fft3/
It's possible we could use process groups on Unix and Windows to handle killing. See:
setpgid
: http://man7.org/linux/man-pages/man2/setpgid.2.htmlAssignProcessToJobObject
: https://msdn.microsoft.com/en-us/library/ms686216(v=vs.85).aspx (http://stackoverflow.com/q/604522/823869)Ah and there's Rust stdlib support for this kind of: https://doc.rust-lang.org/std/os/unix/process/trait.CommandExt.html
Process groups is designed for this sort of thing, and I think I can get it working. However, it has one huge downside, which is that taking child processes out of the parent's group means that Ctrl-C no longer the children automatically (by sending a signal to the parent's entire group). I'm not sure there's a workaround for this that doesn't require the parent to specially handle that signal, as I think shells do.
OMG NO! There's a chance this can work for real. There's a WNOWAIT
flag that a bunch of different interfaces support, to allow waiting without reaping. We could use that to get safe kills? (And waiting using our own library calls on the PID would let us call kill
later on the handle, which is nice.)
This sort of thing seems to be the norm on Windows, where PIDs don't get recycled until all handles are closed. That's actually a lot nicer than Unix :p https://blogs.msdn.microsoft.com/oldnewthing/20110107-00/?p=11803/
Looks like libc
includes waitid
: https://github.com/rust-lang/libc/pull/489
Maybe it's ok to accept a race condition on OSX here? We kind of have to with no pipe2 support anyway.
0304db7b543a266968ab90941a02a0e25d689346
Probably
start
will need to keep more data around. We might need another type of explicit tree to mirror the expression tree, which knows how towait
andkill
its children, similar to Rust's stdlib.