Repository navigation
Tracking Issue for unix_send_signal #141975
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCO-unixOperating system: Unix-likeOperating system: Unix-likeT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Feature gate: #![feature(unix_send_signal)]
This is a tracking issue for API to send a signal to a child process via libc kill.
Public API
// std::os::unix::process
pub trait ChildExt {
fn send_signal(&self, signal: i32) -> Result<()>;
fn send_process_group_signal(&self, signal: i32) -> io::Result<()>;
}
impl ChildExt for std::process::Child { /* ... */ }See also: #156537
Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
- ACP: Add
interruptfunction tostd::process::Childlibs-team#97 - Incomplete implementation Added
interruptfunction forstd::process::Child#101387 - Implementation of
send_signal: Implement send_signal for unix child processes #141990 - Implementation of
send_process_group_signal: AddChildExt::kill_process_group#156539 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should the signal be an
i32or an enum? Should we provide someSIG*constants so the user doesn't have to depend onlibc? See discussion at the ACP Addinterruptfunction tostd::process::Childlibs-team#97 - Is there some reason our preexisting internal implementation took
&mut? See discussion at Implement send_signal for unix child processes #141990. - Fuchsia uses panicking
unimplemented!()but should probably useunsupported()rust/library/std/src/sys/process/unix/fuchsia.rs
Lines 156 to 164 in 5d89371
pub fn send_signal(&self, _signal: i32) -> io::Result<()> { // Fuchsia doesn't have a direct equivalent for signals unimplemented!() } pub fn send_process_group_signal(&self, _signal: i32) -> io::Result<()> { // Fuchsia doesn't have a direct equivalent for signals unimplemented!() }
Footnotes
Reacted by Jonathan Woollett-Light, Dimitris Papaioannou and Trevor Gross
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCO-unixOperating system: Unix-likeOperating system: Unix-likeT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Activity
Rollup merge of rust-lang#141990 - Qelxiros:141975-unix_send_signal, …
Auto merge of #141990 - Qelxiros:141975-unix_send_signal, r=<try>
Auto merge of #141990 - Qelxiros:141975-unix_send_signal, r=<try>
Auto merge of #141990 - Qelxiros:141975-unix_send_signal, r=<try>
Rollup merge of rust-lang#141990 - Qelxiros:141975-unix_send_signal, …
Rollup merge of rust-lang#141990 - Qelxiros:141975-unix_send_signal, …
Rollup merge of rust-lang#141990 - Qelxiros:141975-unix_send_signal, …
Rollup merge of rust-lang#141990 - Qelxiros:141975-unix_send_signal, …
Unrolled build for #141990
Rollup merge of rust-lang#141990 - Qelxiros:141975-unix_send_signal, …
5 remaining items
jmillikin commentedon May 14, 2026
FYI: A new function
send_process_group_signalwas added to this feature in PR #156539tgross35 commentedon Sep 29, 2026
Perhaps to avoid racing with this
rust/library/std/src/sys/process/unix/unix.rs
Lines 1006 to 1011 in 5d89371
waitalready takes&mut selfso that should be fine.tgross35 commentedon Sep 29, 2026
I don't think this is ready for stabilization yet, but nominating for @rust-lang/libs-ping for the two main unresolved questions:
&selfor&mut self? Tracking Issue forunix_kill_process_group#156537 has the same question.@rustbot label +I-libs-nominated
For
&Tvs.&mut T:killandwaittake&mut Teven though they don't strictly have to. I'm not really sure why but perhaps some implementation may want to update some internal data or have a weak guard against racing? Taking&mut selfis probably the easiest answer, since otherwise you could work around the existingkillmutability requirement with.send_signal(SIGKILL).For the second question, I think we should expose a subset of signals to make this more usable without needing
libc. The constants supported by thekillutility could make a reasonable list https://pubs.opengroup.org/onlinepubs/9799919799/utilities/kill.html:SIGHUP,SIGINT,SIGQUIT, SIGABRT,SIGKILL,SIGALRM, andSIGTERM`. I don't have too much of a preference for what this looks like.joshtriplett commentedon Oct 1, 2026
Speaking for myself and not for the rest of libs:
I don't think we should block on bikeshedding a set of signal constants and figuring out which ones we can offer portably.
When we do offer those constants, I think we should take our cues from rustix and not rename them except to 1) strip off the common
SIGprefix in favor of an enum and 2) maybe expand the equivalents ofcreatlikeABRTtoABORTorALRMtoALARM. I don't think, for instance,TERMshould be expanded toTERMINATE.For the first question: I don't think we're providing much of a useful guard by requiring
&mut self, and I think it'd be fine to allow just&self. If you're concerned about workarounds, note thatchild.id()only requires&self, and the PID is all you need to send a signal.thomcc commentedon Oct 2, 2026
I think I would do this as a struct that wraps the i32. Something like
I prefer this because it makes it a bit harder to use the raw signal value, which can be different on different OSes (or architectures within an OS), at least for some signals.
It also gives us a place to put methods or trait impls. I could imagine a
Debugimpl that tells you the name of the signal (at least for the ones we give as constants) would be useful, for example.It's also more obvious in API signatures.
A downside with this (and with option C) is that we already use i32 for signals elsewhere (for example https://doc.rust-lang.org/nightly/std/os/unix/process/trait.ExitStatusExt.html#tymethod.stopped_signal).
It's neither here nor there (since personally I don't prefer the enum approach for this case), but according to https://goals.rust-lang.org/2026/open-enums.html we do have a project goal around open enums, so I'd imagine we'd want to use that if we wanted that. Admittedly, blocking library features we want because of language features we may get someday is... less than ideal. But I think if we went the enum approach and didn't wait for open enums, it would be a bit odd/unfortunate if/when we did get them.
joboet commentedon Oct 4, 2026
waithas to take a mutable reference since it store sthe exit status of the child in the handle, so that it's safe to call multiple times.send_signaldoesn't have any such constraints, and as such I think a shared reference makes more sense. I don't really see whykilltakes a mutable reference – perhaps Windows has some special requirements?ChrisDenton commentedon Oct 6, 2026
It's nothing to do with Windows.
joshtriplett commentedon Oct 6, 2026
We talked about this in today's @rust-lang/libs meeting.
We agreed that we want this operation to be
&self, not&mut self. Nothing it does needs&mut selfand we didn't feel there was semantic value in forcing exclusive ownership.We debated at length whether we wanted to use
i32or usestruct Signal. We didn't fully settle that question, but the trend of the meeting was leaning towardsi32. We have other APIs (ExitStatusExt::signalandExitStatusExt::stopped_signalthat usei32for signals, and we didn't see much value in an opaque type because we aren't offering APIs where there'd be much potential for confusion with otheri32s. Also, our handling of UIDs and GIDs use non-opaque integers as well.Finally, we talked about what to do with constants for signal numbers. We agreed that we want the constants namespaced (e.g.
pub mod sig { ... }). (If we used an opaque type, they'd be associated constants, but if we usei32they should just bepub const.) We didn't finish bikeshedding the naming, but we were roughly leaning in favor of "people using these APIs know the names, don't gratuitously change them". So, for instance,sig::FPErather thansig::FLOATING_POINT_EXCEPTION. (We debated some degree of expanding some of the more obfuscated ones, but also noted that we could offer more than one name for the same constant, e.g.sig::ALRMandsig::ALARM)So, tentatively: let's proceed with
i32, and amod sigcontaining constants for the most useful/portable signals.joshtriplett commentedon Oct 6, 2026
Tentative list of the most useful/portable signals:
ABRTandABORTALRMandALARMBUSCHLDandCLDandCHILDCONTFPEHUPILLINTKILLPIPEQUITSEGVSTOPTSTPSYSTERMTRAPTTINTTOUURGUSR1USR2WINCHNot all of these will be useful with
send_signal, but some will also be useful withExitStatusExtor similar.AFAICT all of these should exist on every Rust target. I've omitted some that wouldn't be. (Notably, PROF, VTALRM, and XCPU, which might not exist on RTEMS. I would ideally like to include those too, but let's get the definitely-available-everywhere subset added first.)