pidfd_prepare(9)
π 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β thestruct pidfor 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 π₯
- Kernel file
./kernel/fork.c set_mm_exe_file(9)replace_mm_exe_file(9)get_mm_exe_file(9)get_task_exe_file(9)get_task_mm(9)dup_mm(9)clone3_stack_valid(9)sys_clone3(9)
okay thatβs the whole page, bestie π source/version: ./kernel; date: October 2026; page: pidfd_prepare(9). periodt β¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms