oconnor663 / shared_child.rs

a wrapper around std::process::Child that lets multiple threads wait or kill at once
MIT License
39 stars 7 forks source link

Add terminate method for nicer shutdown #12

Closed faern closed 7 years ago

faern commented 7 years ago

It would be very nice to be able to shut down child processes in a more graceful way than just killing them.

Would you be willing to add a terminate method? It would probably send SIGTERM on unix and call win32::TerminateProcess on Windows. We can take inspiration from https://github.com/hniksic/rust-subprocess

Then also expose it in your duct crate of course.

oconnor663 commented 7 years ago

I wonder if it makes sense to expose something like PopenExt that lets you send arbitrary signals? Maybe using the signal type from nix::sys::signal::Signal? That should integrate pretty easily into the locks we take now, to avoid all the same race conditions.

faern commented 7 years ago

Yes. It would be nice to add a trait like that on unix based systems. Not sure why we need nix::...::Signal when the signals are defined in libc as c_int. Can't we just take the same type as the underlying mechanism (libc::kill) to send the signal take?

The terminate convenience method would then of course make use of the new signal trait on unix.

faern commented 7 years ago

I'm working on a solution now. It will expose SharedChild::terminate(&self) -> io::Result<()> that is the common interface.

Then I will implement sys::terminate(&SharedChild) that will be used by the above method.

On unix I also have:

pub trait SharedChildExt {
    /// Sends a signal to the child process with `libc::kill`.
    fn send_signal(&self, signal: libc::c_int) -> io::Result<()>;
}

What do you think about this?