Child has the
kill() method to send
SIGKILL to a process.
Does anyone have a recommendation to send
SIGINT or another signal to a process from Rust?
I couldn't find anything in
std or on crates.io.
Based on the source for
std, I think it would be pretty easy to implement myself, but I wanted to avoid that if there is an existing solution.
I reach for the nix crate any time I need something Unix specific. You might want to check it out.
That crate was already included in my project
I think my search for a solution was too specific.
Here is a gist with what I came up with. It requires the
It attempts to stop the process gracefully using
SIGINT, but if that fails or the timeout is reached, it will use
I'm not sure about the error handling because I don't know how I want to handle those in my application.
I'd welcome feedback anyone has about the error handling, code, or general approach.
I recommend using the
It is the simplest solution I have found.
Just fetch the child's id and give it to the kill command:
.args(["-s", "INT", child.id().to_string()])