Process IDs and Identification
You'll learn how the operating system keeps track of every running process using unique numerical identifiers.
What Are Process IDs?
Every process running on your computer needs a way to be uniquely identified by the operating system. Think of it like a social security number for processes—each one gets assigned a Process ID (PID), which is a unique integer that distinguishes it from all other currently-running processes.
When a process creates a child process using fork() (which you learned earlier), the child also needs to know who its parent is. This is tracked using the Parent Process ID (PPID)—the PID of the process that created it.
Why PIDs Matter
PIDs serve several critical purposes:
- Uniqueness: No two running processes share the same PID at the same time
- Reference: System calls like
wait()andwaitpid()use PIDs to specify which process to interact with - Management: Administrators and programs use PIDs to monitor, signal, or terminate specific processes
- Hierarchy tracking: PPIDs help the OS maintain the parent-child process tree
Analogy: Library Card Numbers
Imagine a library where every visitor gets a unique card number (PID). When a parent brings their child, the child gets their own card number, but the library also records the parent's card number (PPID). This way, the library can track who brought whom and manage families of visitors efficiently.
How Processes Learn Their IDs
Processes can query their own identity using system calls like getpid() to retrieve their PID, and getppid() to find their parent's PID. This information is stored in the Process Control Block (PCB) we studied earlier.
Key Takeaway: PIDs uniquely identify every process in the system, while PPIDs track parent-child relationships, enabling the OS to manage process hierarchies effectively.