pidfd_prepare(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– pidfd_prepare(9) πŸ’–

okay so bestie, this is the Kernel API Manual page for pidfd_prepare(9), and it’s lowkey a backstage-pass situation for pidfds. no cap, it’s giving β€œreserve now, install later” energy. πŸŽ€


✨ NAME ✨

pidfd_prepare β€” allocate a new pidfd_file and reserve a pidfd.

🌸 SYNOPSIS 🌸

int pidfd_prepare (struct pid *pid , unsigned int flags , struct file
**ret_file );

πŸŽ€ ARGUMENTS πŸŽ€

  • pid β€” the struct pid for which to create a pidfd. literally the main character here πŸ‘‘
  • flags β€” flags of the new pidfd. the vibe settings ✨
  • ret_file β€” return the new pidfs file. yep, pidfs, not a typo, bestie 🫢

πŸ’… DESCRIPTION πŸ’…

okay so what it does: it will allocate a new file that stashes pid and reserve a new pidfd number in the caller's file descriptor table. the pidfd is reserved but not installed yet β€” very β€œsaved your seat, didn’t sit down” energy πŸ’Ί

the helper verifies that pid is still in use. and heads up: without PIDFD_THREAD, the task identified by pid must be a thread-group leader. that part is fr fr important πŸ‘€

if this function returns successfully, the caller is responsible to either call fd_install passing the returned pidfd and pidfd file as arguments in order to install the pidfd into its file descriptor table, or they must use put_unused_fd and fput on the returned pidfd and pidfd file respectively. no ghosting the cleanup, bestie 😭

this function is useful when a pidfd must already be reserved but there might still be points of failure afterwards and the caller wants to ensure that no pidfd is leaked into its file descriptor table. it’s giving β€œhold the spot so nothing leaks” πŸ’…

🫢 key vibe check: the pidfd is reserved, but not installed yet. do not forget the install-or-cleanup step.

πŸ¦‹ RETURN πŸ¦‹

on success, a reserved pidfd is returned from the function and a new pidfd file is returned in the last argument to the function. slay βœ…

on error, a negative error code is returned from the function and the last argument remains unchanged. sad girl hours, but at least ret_file isn’t touched 😭

πŸ”₯ SEE ALSO πŸ”₯


okay that’s the whole page, bestie πŸ’– source/version: ./kernel; date: October 2026; page: pidfd_prepare(9). periodt ✨

πŸ“¦ where this page comes from