Repository navigation
Tracking Issue for linux_pidfdย #82971
Description
Activity
- addedC-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 RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
on Mar 10, 2021 The PR adds support for obtaining PidFds, but you can't actually do anything with them. Do we want additional methods on
PidFdin std to wait, send signals, obtain the/procdirectory etc. or should that be left to 3rd party crates?52 remaining items
With #150412 I think we should be fairly close to be able to stabilize this for linux.
But I recall that FreeBSD has a similar but more limited API. CC @asomers @MikaelUrankar
Would it make sense to expand this to a common linux + freebsd feature?
I'm not seeing a way to use posix_spawn while still obtaining one of those FDs. And no way to get the exit status from an fd.Sorry, I've not been in-the-loop on this feature. But regarding your questions, @the8472 :
- It's not currently possible on FreeBSD to spawn a new process and get a pidfd without cloning the process's virtual address space. That is, you must do
pdfork+exec. There's nothing likepdposix_spawn. Usingpdfork+execworks, but it's a little less efficient. - There is indeed a way to wait for a child based on its pidfd. But instead of using
wait4, you must usekeventwithEVFILT_PROCDESC. See https://man.freebsd.org/cgi/man.cgi?kevent(2).
- It's not currently possible on FreeBSD to spawn a new process and get a pidfd without cloning the process's virtual address space. That is, you must do
We talked about this in today's libs-api meeting. We'd be interested in having this on FreeBSD under
std::os::freebsd::processtoo if possible so that it's a N=2 API to inform portability.@asomers @MikaelUrankar would you be interested in implementing it?
I'll give it a shot, @the8472 . And BTW, I realized that it's not necessary to use
keventlike I originally thought. Thewait-like functionality can be provided by usingpollorselecton the process file descriptor.How come
PidFd::killis hardcoded to useSIGKILL/PidFd::send_signalisn't public? I think it would be more valuable if you were able to send any signal (or at least valid ones from an enum).- addedT-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.and removedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
on Aug 12, 2026
View all comments
Feature gate:
#![feature(linux_pidfd)]This is a tracking issue for Linux-specific extension methods allowing to obtain process file descriptors for processes spawned with the standard Command API.
Public API
Steps / History
Unresolved Questions
clone3means we can't safely call libc in the child: cargo 1.56 beta hang when run inside Gentoo's sandboxย #89522 (comment)pidfd_openmay work, but it has conditions on avoiding pid-recycling races.Child::pidfd(&self)be removed? It can lead toChild::waitreturning errors instead of a saved exit status ifPidFd::waitobtains the exit status first, which may be surprising behavior.