Processes & the Process Abstraction

a process identifier (PID)

/ P-I-D, or 'pid' /

When you call a busy clinic, you are given a number so they can refer to you unambiguously even if two patients share a name. A process identifier, or PID, is that number for a process: a unique integer the operating system assigns to each running process so it (and you) can name and act on exactly that process and no other.

When the OS creates a process, it picks an unused integer as the PID and records it in the process's PCB. Tools and system calls then use the PID to refer to the process: a command might list a process by its PID, and a system call might send a signal to a given PID to ask that process to stop. PIDs are unique among currently-running processes, but they are reused over time: once a process ends and is fully cleaned up, its number can later be handed to a brand-new, unrelated process. On Unix-like systems the very first process gets PID 1, and a process can ask for its own PID and its parent's PID.

PIDs matter because they are the handle the rest of the system uses to talk about a specific process: kill a process, check its status, set its priority, or trace it, all by PID. A subtle hazard follows from reuse: code that remembers a PID and acts on it later might, after the original process has exited, accidentally hit a different process that has since inherited that number, which is why long-lived references to processes need more care than just storing a PID.

If a runaway process has PID 4521, an administrator can stop it with a command like 'kill 4521', which sends a signal to exactly the process holding that PID.

The PID is how commands and system calls name one specific process.

PIDs are reused. A PID uniquely names a process only while it is alive; after it exits, the same number may later belong to a completely different process.

Also called
PIDprocess ID行程編號行程 ID