getpid(2)
๐ getpid(2) โ the system calls manual, but make it cute ๐
okay bestie, welcome to the System Calls Manual page for getpid and getppid, aka the two tiny little functions that tell a process who it is and who made it. it's giving "find your birth certificate but for your own PID" ๐ผโจ
๐ธ NAME ๐ธ
getpid, getppid โ get process identification ๐
๐ LIBRARY ๐
Standard C library (libc, -lc). the classic. the icon. the one your linker already links against, no cap ๐
โจ SYNOPSIS โจ
#include <unistd.h>
pid_t getpid(void);
pid_t getppid(void);
that's it. two lines. no arguments. no drama. literally the least demanding functions in the whole syscall universe ๐ซถ
๐ฆ DESCRIPTION ๐ฆ
okay so, getpid() returns the process ID (PID) of the calling process. that's it, that's the whole thing. and just so you know, this is often used by routines that generate unique temporary filenames โ so if you've ever written a temp file helper, this is basically your backbone, bestie. iykyk ๐
and then getppid() returns the process ID of the parent of the calling process. and here's the tea: the "parent" here is either the ID of the process that created this process using fork(), or โ and this is the part where things get a lil spicy ๐ถ๏ธ โ if that process has already terminated, it returns the ID of the process to which this process has been reparented. and that reparenting target is either init(1) or a "subreaper" process defined via the prctl(2) PR_SET_CHILD_SUBREAPER operation. so like, your parent can change and that's valid, we support reparenting in this house ๐โจ
๐ญ ERRORS ๐ญ
these functions are always successful. no errors. not even one. not even a little one. they simply cannot fail. the way that a syscall can just be perfect and unproblematic... obsessed ๐๐
๐ VERSIONS ๐
so on Alpha, instead of having a whole pair of getpid() and getppid() system calls, there's a single getxpid() system call that returns a pair of PID and parent PID. it's giving two-for-one deal ๐
and the glibc getpid() and getppid() wrapper functions transparently deal with this โ so you never even notice. if you wanna know about register mapping details, go peek at syscall(2). yes, register mapping. yes it's deeply nerdy. yes we love it ๐ง
๐ STANDARDS ๐
POSIX.1-2024. certified. ratified. slay โญ
๐ HISTORY ๐
4.3BSD, SVr4, POSIX.1-1988. ancient. legendary. still standing. periodt ๐
๐ง C library/kernel differences ๐ง
okay so buckle up bestie, this is the ancestral drama section and it is juicy ๐
from glibc 2.3.4 up to and including glibc 2.24, the glibc wrapper function for getpid() cached PIDs, with the goal of avoiding additional system calls when a process calls getpid() repeatedly. makes sense, right? efficiency girlie ๐ซ
normally this caching was invisible. normally. but its correct operation relied on support in the wrapper functions for fork(2), vfork(2), and clone(2). so if an application bypassed the glibc wrappers for these system calls by using syscall(2), then a call to getpid() in the child would return the wrong value โ to be precise: it would return the PID of the parent process ๐ญ
and it gets worse. there were cases where getpid() could return the wrong value even when invoking clone(2) via the glibc wrapper function. (for a discussion of one such case, see BUGS in clone(2).) furthermore, the complexity of the caching code had been the source of a few bugs within glibc over the years. so like... the cache was lowkey a menace ๐
and because of the aforementioned problems, since glibc 2.25, the PID cache is removed: calls to getpid() always invoke the actual system call, rather than returning a cached value. the cache got cancelled. we do not miss her. main character behavior honestly ๐
bestie please internalise this one: if you're on old glibc (< 2.25) and you're raw-doggingsyscall(2)forfork/vfork/clone, your child'sgetpid()might be lying to your face. that's not a vibe. that's a bug ๐
๐ NOTES ๐
if the caller's parent is in a different PID namespace (see pid_namespaces(7)), getppid() returns 0. zero. nada. no parent for you in this namespace, bestie, go touch grass ๐ง
also, from a kernel perspective, the PID (which is shared by all of the threads in a multithreaded process) is sometimes also known as the thread group ID (TGID). this contrasts with the kernel thread ID (TID), which is unique for each thread. for further details, see gettid(2) and the discussion of the CLONE_THREAD flag in clone(2). so like, PID = the whole group chat, TID = the individual member. TGID is literally the group chat name ๐ธ
๐ SEE ALSO ๐
clone(2), fork(2), gettid(2), kill(2), exec(3), mkstemp(3), tempnam(3), tmpfile(3), tmpnam(3), credentials(7), pid_namespaces(7)
go read them. not me being a bad influence and giving you eleven more manpages to read ๐โจ
and that's the whole page, bestie!! this was Linux man-pages 6.20, dated 2026-02-08 ๐ thanks for reading all the way to the bottom, you're literally the best, go get your PID and feel something ๐ซถ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Rickard E. Faith <faith@cs.unc.edu>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms