Process
A process is a running instance of a program. Linux gives each process a unique PID, its own memory space, and its own table of open file descriptors.
Understanding Linux Processes
What Is a Process in Linux?
A program is a file on disk. A process is that program loaded into memory and executing, with private memory, open files, and a state. Installed nginx is a program, and systemctl start nginx turns it into running processes, a master plus workers. When you troubleshoot a hung service, you inspect processes: their state, memory use, and signals.
How Processes Are Created
Linux creates a process by calling fork() to copy the parent, then exec() to replace the copy with a new program. The child inherits the parent's environment and open file descriptors. Every process has a parent, except PID 1, forming a tree.
PID 1 systemd +-- sshd (892) | +-- bash (1203) | +-- vim (1247) +-- nginx master (1100) | +-- nginx worker (1101) +-- postgres (1350)Process States
R Running or ready to runS Sleeping, waiting for an event (can be interrupted)D Uninterruptible sleep, usually waiting on disk or NFS I/OT Stopped by a signalZ Zombie: finished, parent has not collected its exit statusA D state process cannot be killed until its I/O completes, and many of them raise the load average even while the CPU is idle.
Practical Process Commands
ps aux # snapshot of all processesps --forest -eo pid,ppid,stat,cmd # tree viewpstree -pps -eLf | grep nginx # include threads top # live view; press M for memory, P for CPUhtop # friendlier interface cat /proc/1234/statustr '\0' ' ' < /proc/1234/cmdlinels -la /proc/1234/fdTroubleshooting Processes
| Symptom | Command | What to Look For |
|---|---|---|
| Server slow | top or htop |
Top CPU or memory user |
| Cannot kill a process | ps -o stat= -p PID |
D state, waiting on I/O |
| Zombies piling up | ps -eo stat,pid,ppid,cmd | grep '^Z' |
Parent not reaping |
| Unexpected root process | ps -eo user,pid,cmd |
Services running as root |
TipMany D-state processes point to the I/O layer, not the processes. Check
iostat -xanddmesgfor disk or NFS problems.
SecurityService processes should run as dedicated low-privilege accounts. An unexpected root-owned process deserves investigation.
Remember
ps auxis a snapshot. Usetoporhtopto watch an intermittent spike change over time.
Frequently Asked Questions
What happens to child processes when the parent dies?
They are re-parented to PID 1 (or a subreaper), which reaps them when they exit. In containers the app often runs as PID 1 without reaping logic, so tools like tini are added.
What is the difference between SIGTERM and SIGKILL?
SIGTERM asks a process to exit and can be caught so it can clean up. SIGKILL is enforced by the kernel and cannot be caught, so there is no cleanup. Try SIGTERM first and escalate only after a timeout.
What is the difference between a process and a thread?
Processes have separate memory spaces. Threads belong to one process and share its memory and open files, which makes them lighter but easier to corrupt each other.