GETPID(2)
π getpid(2) β the System Calls Manual page, but make it cute π
okay bestie so we're in the System Calls Manual, section 2, and today's main character is getpid(2). pull up a chair, grab a boba, we're gonna learn how a process finds out who it is. π«Ά
β¨ NAME β¨
getpid, getppid β get parent or calling process identification
like. it's literally the "who am i" and "who made me" of syscalls. identity crisis: solved. π
π LIBRARY π
Standard C Library (libc, -lc)
yes you gotta link the libc, that's the vibe, that's the whole situation. π
πΈ SYNOPSIS πΈ
#include <unistd.h>
pid_t
getpid(void);
pid_t
getppid(void);
two functions. both take void β aka they take nothing, they just know. no arguments, no notes, iconic behavior. β¨
π« DESCRIPTION π«
okay so. the getpid() system call returns the process ID of the calling process. that's it, that's the whole thing β it looks in the mirror and tells you its PID. πͺ
β οΈ but bestie, listen, this is the important part: though the ID is guaranteed to be unique, it should NOT be used for constructing temporary file names, for security reasons. like do not do it. see mkstemp(3) instead. i am begging you. this is a real security thing, not a vibe thing. π₯
and the getppid() system call returns the process ID of the parent of the calling process. so like, your process's mom. your process's origin story. the one who forked you into existence. ππ
π¨ ERRORS π¨
not today, satan, because the getpid() and getppid() system calls are always successful, and no return value is reserved to indicate an error.
no error codes. no errno drama. no "it depends." they just work. flawless victory. π
π SEE ALSO π
the group chat of related syscalls, go read them, they're all slaying:
π STANDARDS π
the getpid() and getppid() system calls are expected to conform to ISO/IEC 9945-1:1990 (βPOSIX.1β). so like, they're certified. official. standards-approved. not me being impressed but also yes me being impressed. β
π¦ HISTORY π¦
the getpid() function appeared in Version 7 AT&T UNIX. ancient. vintage. a true elder of the game. respect your elders fr fr. π
and that's the tea, bestie β this page came to you from the Debian crew, dated December 15, 2015, and no cap, that's genuinely all there is to know. go call getpid() on yourself, you deserve to know who you are. πβ¨π
π¦ 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) 1980, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms