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_ino field 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 of pidfd/pidfs internals. 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 and name_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