Process Management
Every program running on your system is a process. Understanding how Linux manages processes — how to inspect them, control them, and kill them — is essential for anyone working with Linux seriously.
Series: Learning Linux from Scratch
- 1. Learning Linux from Scratch — After a Full IT Apprenticeship
- 2. What is Linux?
- 3. The Filesystem
- 4. Users and Permissions
- 5. Installing and Managing Software
- 6. Text Editors
- 7. Shell Scripting Basics
- 8. Process Management
- 9. Networking Fundamentals
- 10. SSH
- 11. systemd and Services
- 12. Disk Management
- 13. Users and Groups — In Depth
- 14. Cron and Scheduled Tasks
- 15. Firewall — iptables and ufw
- 16. Environment Variables and the Shell
- 17. Log Management
- 18. Kernel Module Management
- 19. The /proc Filesystem — In Depth
- 20. The /sys Filesystem and udev
- 21. Kernel Parameters and sysctl
- 22. Compiling and Installing a Custom Kernel
Every program running on your system is a process. Your terminal is a process. Your browser is a process. The SSH daemon waiting for connections in the background is a process. Understanding how Linux manages all of these is essential for working with the OS seriously.
What is a process?
When you run a program, the kernel creates a process for it. That process gets a unique identifier called a PID — Process ID. Every process also has a PPID — Parent Process ID — because every process was started by another process.
The first process on any Linux system is systemd (or init on older systems). It has PID 1. Every other process on the system is a descendant of it.
Viewing processes
ps
ps shows a snapshot of currently running processes.
psBy default it only shows processes in your current terminal session. To see everything:
ps auxa— show processes from all usersu— show the user that owns each processx— include processes not attached to a terminal
The output looks like this:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 168548 11320 ? Ss 09:00 0:01 /sbin/init
jan 1234 0.1 0.5 123456 45678 pts/0 Ss 09:05 0:00 bash
jan 5678 2.3 1.2 234567 98765 pts/0 R+ 09:10 0:03 firefox
The STAT column shows the process state:
R— runningS— sleeping (waiting for something)Z— zombie (finished but not yet cleaned up by parent)T— stopped
pgrep
Instead of grepping through ps output, use pgrep to find a process by name:
pgrep firefoxReturns the PID. Add -l to also show the name:
pgrep -l firefoxtop and htop
top gives you a live, updating view of running processes sorted by CPU usage:
tophtop is the same but with a much more readable interface and mouse support. Install it if it is not already there:
sudo apt install htop
htopIn htop, F6 sorts by a column, F9 opens the kill menu, F10 exits.
Foreground and background jobs
When you run a command in the terminal, it runs in the foreground. Your terminal is blocked until it finishes. To run a command in the background, add &:
sleep 60 &The shell prints the job number and PID, then returns the prompt immediately.
[1] 4821
To see your background jobs:
jobsTo bring a background job back to the foreground:
fg %1To send a running foreground process to the background, press Ctrl + Z to suspend it, then:
bg %1Signals and kill
Signals are how you communicate with processes. The most common use is stopping them.
kill PIDBy default kill sends the SIGTERM signal (signal 15), which asks the process to terminate gracefully. The process can catch this signal and clean up before exiting.
If a process is not responding to SIGTERM:
kill -9 PID-9 is SIGKILL. This cannot be caught or ignored by the process. The kernel terminates it immediately. Use this as a last resort — the process has no chance to clean up.
To kill by name instead of PID:
pkill firefoxCommon signals:
| Signal | Number | Meaning |
|---|---|---|
| SIGTERM | 15 | Graceful termination (default) |
| SIGKILL | 9 | Immediate termination |
| SIGHUP | 1 | Hangup — often used to reload config |
| SIGSTOP | 19 | Pause a process |
| SIGCONT | 18 | Resume a paused process |
Process priority — nice and renice
Every process has a priority value called niceness, ranging from -20 (highest priority) to 19 (lowest priority). The default is 0.
Start a process with a lower priority:
nice -n 10 ./my-script.shChange the priority of a running process:
renice -n 5 -p PIDOnly root can set negative nice values (higher than default priority).
/proc
Every process has a corresponding directory in /proc named after its PID. This directory contains detailed information about the process as virtual files.
cat /proc/1/statusUseful files inside a process directory:
status— human readable process infocmdline— the command that started the processenviron— environment variablesfd/— open file descriptors
ls /proc/1/fdShows every file the process currently has open.
Understanding processes is what separates someone who uses Linux from someone who can actually administer it. When a system is slow, you look at processes. When something is unresponsive, you send signals. When something is consuming too much CPU, you renice it.
Next up: networking fundamentals — IP addresses, interfaces, and the tools to inspect and debug them.