Operating systems · foundation
Process and PID
A process is an operating-system execution context for a running program, including its memory, credentials, and open resources. A process ID (PID) is the number the OS uses to identify that process within a PID namespace for its current lifetime.
Why it matters
Commands such as ps, kill, wait, and top act on processes, often by PID. Knowing that PIDs can be reused prevents monitoring and automation from treating a number as a permanent identity.
Mental model
How to reason about process and pid
Picture the kernel maintaining a process table. A PID is an index-like handle into a live entry; when that process exits, the entry disappears and the number may later identify a different process.
Analogy
A PID is like a restaurant table number: it identifies the current occupant well enough for service, but the same number can belong to someone else after the table is cleared.
Examples
See the boundary, not just the happy path
Worked example · Inspect the current shell
ps -p $$ -o pid=,ppid=,stat=,comm=The shell expands $$ to its own PID, and ps asks the kernel for that live process's parent, state, and command name. The PID selects a process; it does not describe what that process is doing.
Worked example · Signal a known process
kill -TERM 4821kill requests that the kernel deliver SIGTERM to the process currently identified by PID 4821. Delivery can fail if the PID does not exist or the caller lacks permission.
Useful contrast · Program file versus process
/usr/bin/python3 can back several processes at onceThe executable file is persistent program code. Each invocation creates a distinct process with its own PID, address space, and resources.
Common mistakes
Misconceptions to remove early
Treating a PID as a permanent identity
The OS may recycle a PID after its process has been reaped. Long-running supervisors should pair a PID with stronger evidence such as a start time or a kernel-provided process handle.
Using process and program interchangeably
A program is executable code and data; a process is one running instance. One program can have many simultaneous processes.
Quick check
Can you predict the result?
1. What can PID 4821 mean after its original process has exited and been reaped?
- • It may later identify an unrelated process because PIDs can be reused.
- • It permanently identifies the original executable file.
- • It becomes reserved until the machine reboots.
2. Why can two running instances of the same executable have different PIDs?
Keep building