PDFORK(2)
π PDFORK(2) π β the pdfork, pdgetpid, pdkill girlies (system calls to manage process descriptors)
okay bestie, sit down, hydrate, because we're about to talk about process descriptors and honestly? they're iconic. this is PDFORK(2) from the System Calls Manual and it's giving "I manage processes but make it fashion" π
π LIBRARY
Standard C Library (libc, -lc) β she's in libc, she's always been in libc, we love her for that π«Ά
β¨ SYNOPSIS β¨
#include <sys/procdesc.h>
pid_t
pdfork(int *fdp, int flags);
int
pdgetpid(int fd, pid_t *pidp);
int
pdkill(int fd, int signum);
πΈ DESCRIPTION πΈ
okay so process descriptors?? they're special file descriptors that literally represent processes. main character energy fr fr. you make them with pdfork(), which is basically fork(2) but with β¨auraβ¨ β and if it works, it hands you back a process descriptor in the integer that fdp points to.
lowkey important: processes made withpdfork()will not causeSIGCHLDwhen they terminate. no drama, no signal, she just leaves. π
and pdfork() takes these flags, bestie:
PD_DAEMONβ instead of the default "terminate when you close me" behaviour, this lets the process just live, chilling, until someone explicitly kills it withkill(2).
not permitted incapsicum(4)capability mode (go readcap_enter(2), iykyk).
PD_CLOEXECβ sets close-on-exec on the process descriptor. classic, iconic, hygienic. π
then there's pdgetpid() which queries the process ID (PID) inside the process descriptor fd. it's the "hey girl what's your PID" of system calls.
and pdkill() is functionally identical to kill(2), except instead of a PID she accepts a process descriptor, fd. same energy, different handle. periodt.
π¦ the other system calls that also act different around process descriptors π¦
fstat(2)β queries the status of a process descriptor. rn only thest_mode,st_birthtime,st_atime,st_ctimeandst_mtimefields are defined. and here's the vibe check: if the owner read, write, and execute bits are set, the process represented by the process descriptor is still alive. πpoll(2)andselect(2)β let you wait for process state transitions. rn onlyPOLLHUPis defined, and it gets raised when the process dies. π you can also monitor process state transitions with thekqueue(2)filterEVFILT_PROCDESC; rn onlyNOTE_EXITis implemented.close(2)β will close the process descriptor unlessPD_DAEMONis set. and if the process is still alive and this is the last reference to the process descriptor, the process gets terminated with the signalSIGKILL. π no cap. that's the default terminate-on-close behaviour and she does not play.
π₯ RETURN VALUES π₯
pdfork()returns a PID,0or-1, exactly asfork(2)does. same rules, same numbers.pdgetpid()andpdkill()return0on success and-1on failure.
π ERRORS π
these functions may return the same error numbers as their PID-based equivalents (like, pdfork() may return the same error numbers as fork(2)), plus these additions:
[EINVAL]β the signal number you gave topdkill()is invalid. bestie. that's not a real signal. π«[ENOTCAPABLE]β the process descriptor being operated on has insufficient rights (e.g.CAP_PDKILLforpdkill()). she doesn't have the clearance, hun. π
π SEE ALSO π
close(2), fork(2), fstat(2), kill(2), poll(2), kqueue(2), wait4(2), capsicum(4), procdesc(4)
go read them, they're all part of the lore. π
β HISTORY β
the pdfork(), pdgetpid(), and pdkill() system calls first appeared in FreeBSD 9.0. π«
support for process descriptors mode was developed as part of the TrustedBSD Project.
π AUTHORS π
these functions and the capability facility were created by Robert N. M. Watson <rwatson@FreeBSD.org> and Jonathan Anderson <jonathan@FreeBSD.org> at the University of Cambridge Computer Laboratory, with support from a grant from Google, Inc. absolute legends, we stan. π«Άβ¨
and that's the whole page, bestie!! this came from the Debian build, dated October 14, 2018 β so yeah, throwback era, but the lore still hits. ππ¦ mwah, go manage some processes. π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2009-2010, 2012-2013 Robert N. M. Watson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms