Skip to main content

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.

◈ DIAGRAM
PID 1 systemd
+-- sshd (892)
| +-- bash (1203)
| +-- vim (1247)
+-- nginx master (1100)
| +-- nginx worker (1101)
+-- postgres (1350)

Process States

TEXT
R Running or ready to run
S Sleeping, waiting for an event (can be interrupted)
D Uninterruptible sleep, usually waiting on disk or NFS I/O
T Stopped by a signal
Z Zombie: finished, parent has not collected its exit status

A 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

Bash
ps aux # snapshot of all processes
ps --forest -eo pid,ppid,stat,cmd # tree view
pstree -p
ps -eLf | grep nginx # include threads
top # live view; press M for memory, P for CPU
htop # friendlier interface
cat /proc/1234/status
tr '\0' ' ' < /proc/1234/cmdline
ls -la /proc/1234/fd

Troubleshooting 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
Tip

Many D-state processes point to the I/O layer, not the processes. Check iostat -x and dmesg for disk or NFS problems.

Security

Service processes should run as dedicated low-privilege accounts. An unexpected root-owned process deserves investigation.

Remember

ps aux is a snapshot. Use top or htop to 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.

Found a mistake, an outdated step or a broken link?