Add std::process::Child::terminate
as an alternative to std::process::Child::kill
#118045
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have frequently used
std::process::Child::kill
and/orkill_on_drop(true)
since it's in the standard library, but I think it's probably better for people to useSIGTERM
if they can. There's lots of use-cases where a subprocess might want to do some last-minute stuff before exiting, right?Many cleanup steps, like closing files, are handled in Linux automatically, but sometimes a process might want to cleanup something through the network (logging, shared resources between machines).
Also, the standard Linux utility
kill
sendsSIGTERM
by default, and I've always understood that this is becauseSIGKILL
should only be used if a process doesn't respond toSIGTERM
.The Python standard library module
subprocess
has some precedent for this: it provideskill
,terminate
, andsend_signal
. [1] I figure we could start by addingterminate
, because that's probably the next-most-common signal that people use.Let me know what you guys think: my understanding from the dev-guide is that making API Change Proposals is optional, and this is a pretty small change, so I figured I'd just send a PR.
By the way, I did consider implementing this as an extension to the Linux
ChildExt
, sinceSIGTERM
is only applicable on Unix, but the Python library avoids this complexity by just implementingterminate()
the same way askill()
on Windows and other platforms. I figured we might as well just follow the Python standard library here, it seems reasonable.[1] https://docs.python.org/3/library/subprocess.html#subprocess.Popen.terminatehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.terminate