SD_PIDFD_GET_INODE_ID(3)
π sd_pidfd_get_inode_id(3) β the manual page, bestie edition π
okay so this is the sd_pidfd_get_inode_id(3) page from the systemd manual (section 3, the library-functions girlies). it's short, it's sweet, it's giving "one function, big opinions." let's get into it π
β¨ NAME β¨
sd_pidfd_get_inode_id β grab the 64-bit inode ID of a PID file descriptor (aka a PIDFD), no cap π¦
β¨ SYNOPSIS β¨
#include <systemd/sd-daemon.h>
int sd_pidfd_get_inode_id(int pidfd, uint64_t *ret);
β¨ DESCRIPTION β¨
so you can call sd_pidfd_get_inode_id() when you wanna acquire the 64-bit inode ID of a PID file descriptor (a PIDFD, iykyk). and bestie, the whole point of this number is that you can use it to reliably identify a process for the current boot. that's the vibe. β¨
classic example incoming: the service manager sets the $MAINPIDFDID and $MANAGERPIDFDID environment variables β those are the inode IDs of the service main process and the service manager itself, respectively β but only if the kernel supports that functionality. if the kernel isn't serving, you're not getting the env vars, periodt. π
now here's the tea on 64-bit vs 32-bit architectures, because this is literally why the function exists:
- on 64-bit architectures you can just call
fstat(2)on a given pidfd and the inode ID falls right out. easy. iconic. π - on 32-bit architectures though?
struct stat's.st_inofield is also 32-bit, which β much like PIDs β is subject to reuse. π« not the reliable-boot-identity vibe we're going for. - so a second mechanism leveraging
name_to_handle_at(2)was added to the kernel in v6.14. and this helper? it's here to simplify downstream handling ofpidfd/pidfsinternals. slay. π§
β¨ RETURN VALUE β¨
on success, the function returns 0 or a positive integer. π
on failure, you get a negative errno-style error code back. π (that's the "not me getting an error" moment.)
Errors πΈ
the returned errors may mean any of the following situations, so read carefully bestie:
-EOPNOTSUPPβ the stable PIDFD inode ID is not supported by the running kernel, or the system is 32-bit andname_to_handle_at()is unavailable. π-EBADFβ the file descriptor you handed over is invalid, or it's just... not a PIDFD. wrong vibe entirely. π
β¨ NOTES β¨
the functions described here are available as a shared library, and you can compile against it and link to it with the libsystemd pkg-config(1) file. π«Ά that's the whole note. short and sweet.
β¨ HISTORY β¨
sd_pidfd_get_inode_id() was added in version 258. new-ish girl on the block, but she's doing great. β
β¨ SEE ALSO β¨
π friendly reminder from your local unix bestie: every option, error, env var and version number above is exactly what the page says β the personality is mine, the facts are theirs. don't @ me. π
and that's the page!! this manual came to you courtesy of systemd 262.1 (the SD_PIDFD_GET_INODE_ID(3) page itself, section 3). go forth and identify your processes reliably for the current boot, queen. π
β¨π
π¦ where this page comes from
- arch rolling: systemd-libs 262.1-1 Β· LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later WITH Linux-syscall-note
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms