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