Linux Tutorial / PID and PPID Explained: Find and Manage Processes
A PID (process ID) identifies a running process. A PPID (parent process ID) identifies the current parent process; that parent can change after reparenting. On Linux, these numbers help you find a process, inspect its parent-child relationship, and send a signal to a specific process when necessary. The kernel assigns the numbers; you manage the processes they currently identify, not the PID numbers themselves.
What is the difference between a PID and a PPID?
A process is a running instance of a program. Running the same program twice normally creates two processes with different PIDs. When one process creates another, the new process also has a PPID pointing to its parent.
| Field | Meaning | Why it matters |
|---|---|---|
| PID | The current process's identification number | Select a particular process for inspection or signaling |
| PPID | The PID of the current process's parent | Identify the creator and inspect parent-child relationships |
For example, if a shell has PID 4250 and a sleep process started by that shell has PID 4321, the sleep process may show 4250 as its PPID. These numbers are illustrative. A PID is not a permanent identifier: after a process exits, its number can be reused. In environments with PID namespaces, such as containers, the same process can also appear under different PID numbers depending on where it is observed.
How can you check a process's PID and PPID?
The most direct method is to ask ps for the columns you need. In Bash, $$ expands to the current shell's PID, so the following command displays information about that shell:
ps -p "$$" -o pid,ppid,user,stat,etime,args
The output depends on your environment. PID is the shell's own number, while PPID identifies its parent. USER names the owner, STAT shows process state, ELAPSED shows how long it has been running, and COMMAND or ARGS shows the command.
PID PPID USER STAT ELAPSED COMMAND
4250 4110 learner Ss 00:42 -bash
The numbers and user name above are sample output, not values to expect on your system. You can inspect a known PID with ps -p 4321 -o pid,ppid,args; if that process has exited, no matching process row appears. To list all currently visible processes, use ps -eo pid,ppid,user,stat,args. Pipe a long list to less if you need to browse it.
To find a PID by process name, try pgrep -a -x sleep. The -x option requires an exact process-name match, and -a includes the command line. Several processes may share the same name, so a matching PID alone does not prove you found your own job. The ps command guide and pgrep command guide explain the options in more detail.
Inspect parent-child relationships without changing processes
Use process and job management for the basic create-and-signal exercise. Here, inspect the current shell and its direct children without terminating anything. The inspecting ps command can itself appear as a temporary child, and processes may exit between queries.
ps -p "$$" -o pid,ppid,user,lstart,args
ps --ppid "$$" -o pid,ppid,stat,args
In interactive Bash, $$ identifies that shell. Inside a parenthesized Bash subshell, it can retain the parent Bash value; distinguish $BASHPID when you need the current Bash process. If installed, pstree -p "$$" provides an optional tree view.
Distinguish PID namespaces from PID reuse
The same process can have different PIDs as seen from a host and a container. These commands read the current shell’s PID namespace identifier and the PID hierarchy visible through this proc filesystem. A single namespace may show only one NSpid value; kernel configuration, proc visibility, and permissions can limit the result.
readlink "/proc/$$/ns/pid"
grep '^NSpid:' "/proc/$$/status"
A namespace difference reflects the observer’s location. PID reuse occurs when a later process receives a number previously used by an exited process. Do not confuse the two or mix host and container PIDs when signaling.
What happens if a parent exits or a PID changes?
Ending a parent does not necessarily end all of its children. A surviving child can be reparented to another process, so its PPID can change. Do not assume that signaling one parent PID cleans up every process below it.
Conversely, a child that has exited but whose parent has not yet collected its exit status can briefly remain as a zombie process. The child is no longer running, so repeatedly sending KILL to that PID is not the solution. Check how the parent reaps its children. Bash's wait can collect the exit status of a child created by that shell.
A PID identifies a process at a particular time. Do not choose a termination target solely from an old PID file or a number written down earlier. Check the command, owner, and start time together. When working inside and outside a container, take care not to confuse PID numbers from different namespaces.
How should you manage a service process?
A service managed by systemd may receive a different PID after it restarts. In that situation, inspect and manage the service unit rather than signaling one PID directly. For example, if nginx.service is actually installed, systemctl status nginx.service checks its status. Use sudo systemctl restart nginx.service only when a restart is operationally appropriate. If nginx is not installed or the system uses another service manager, verify the correct service name and management method first.
A PID helps you identify a particular process; a PPID helps you understand its parent relationship. Before stopping work, narrow down the exact target rather than signaling every process with a matching name. For a managed system service, use its service manager.
PID namespace documentation and proc status field documentation explain visibility and the NSpid field.
Primary references
The ps(1), pgrep(1), pstree(1), and kill(1) manuals describe inspection and signaling. The Bash special parameters and Bash job-control builtins documents explain $$, $!, and wait. See wait(2) for parent termination and zombie processes.




