pidfs: provide information after task has been reaped Hey, Various tools need access to information about a process/task even after it has already been reaped. For example, systemd's journal logs and uses such information as the cgroup id and exit status to deal with processes that have been sent via SCM_PIDFD or SCM_PEERPIDFD. By the time the pidfd is received the process might have already been reaped. This series aims to provide information by extending the PIDFD_GET_INFO ioctl to retrieve the exit code and cgroup id. There might be other stuff that we would want in the future. Pidfd polling allows waiting on either task exit or for a task to have been reaped. The contract for PIDFD_INFO_EXIT is simply that EPOLLHUP must be observed before exit information can be retrieved, i.e., exit information is only provided once the task has been reaped. Note, that if a thread-group leader exits before other threads in the thread-group then exit information will only be available once the thread-group is empty. This aligns with wait() as well, where reaping of a thread-group leader that exited before the thread-group was empty is delayed until the thread-group is empty. With PIDFD_INFO_EXIT autoreaping might actually become usable because it means a parent can ignore SIGCHLD or set SA_NOCLDWAIT and simply use pidfd polling and PIDFD_INFO_EXIT to get get status information for its children. The kernel will autocleanup right away instead of delaying. To: Oleg Nesterov <oleg@redhat.com> Cc: linux-fsdevel@vger.kernel.org Cc: Jeff Layton <jlayton@kernel.org> Cc: Lennart Poettering <lennart@poettering.net> Cc: Daan De Meyer <daan.j.demeyer@gmail.com> Cc: Mike Yuan <me@yhndnzj.com> Signed-off-by: Christian Brauner <brauner@kernel.org> --- Changes in v3: - Fix various minor issues. - Link to v2: https://lore.kernel.org/r/20250304-work-pidfs-kill_on_last_close-v2-0-44fdacfaa7b7@kernel.org Changes in v2: - Call pidfs_exit() from release_task(). - Don't provide exit information once the task has exited but once the task has been reaped. This makes for simpler semantics. Thus, call pidfs_exit() from release_task(). - Link to v1: https://lore.kernel.org/r/20250228-work-pidfs-kill_on_last_close-v1-0-5bd7e6bb428e@kernel.org --- b4-submit-tracking --- # This section is used internally by b4 prep for tracking purposes. { "series": { "revision": 3, "change-id": "20250227-work-pidfs-kill_on_last_close-a23ddf21db47", "prefixes": [], "base-branch": "vfs-6.15.pidfs", "history": { "v1": [ "20250228-work-pidfs-kill_on_last_close-v1-0-5bd7e6bb428e@kernel.org" ], "v2": [ "20250304-work-pidfs-kill_on_last_close-v2-0-44fdacfaa7b7@kernel.org" ] } } }