A process is a program being run. Every command you start creates a process identified by a unique number called a PID. Knowing how to list and watch processes is essential to understand what is running on your system.
What you will learn
- What a process and a PID are
- List processes with
psandps aux - Read the information of
top - Start a process in the background with
& - Switch between foreground and background: Ctrl+Z,
fg,bg,jobs
What is a process?
When you type a command, the system creates a process to run it. This process:
- has a PID (Process ID): a unique number,
- has a parent process (PPID), identified by its own PID,
- belongs to a user,
- uses memory and CPU.
The very first process of the system is init (or systemd on modern
distributions), with PID 1. Every process started in user space
descends from it; only kernel threads (internal tasks of the system, which
belong to no program) depend on another ancestor, kthreadd, with PID 2.
How do you list processes with ps?
ps takes a snapshot of the processes at the moment you type it. Without
options it only shows your terminal; with aux it shows the whole
system.
Your processes
ps PID TTY TIME CMD 1234 pts/0 00:00:00 bash 1256 pts/0 00:00:00 psEverything started elsewhere, services and other sessions included, stays invisible here.
Every process on the system
ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.1 169624 13412 ? Ss 08:00 0:01 /sbin/initroot 412 0.0 0.1 32120 8744 ? Ss 08:00 0:00 /usr/sbin/sshdbob 1234 0.0 0.0 8536 5200 pts/0 Ss 09:15 0:00 -bashbob 1300 0.5 1.2 245680 98200 pts/0 S+ 10:00 0:03 python3 script.pyEach column has a meaning:
| Column | Meaning |
|---|---|
USER | Owner of the process |
PID | Unique identifier of the process |
%CPU | Percentage of processor use |
%MEM | Percentage of memory use |
VSZ | Virtual memory allocated (in KiB) |
RSS | Memory actually used (in KiB) |
TTY | Associated terminal (? = no terminal) |
STAT | State of the process |
START | Start time |
TIME | CPU time used |
COMMAND | Command that started the process |
Filter with grep
To look for a specific process:
ps aux | grep sshdroot 412 0.0 0.1 32120 8744 ? Ss 08:00 0:00 /usr/sbin/sshdbob 1350 0.0 0.0 6420 720 pts/0 S+ 10:05 0:00 grep sshdProcess states (STAT)
The STAT column of ps aux sums up in one or two letters what a
process is doing at the moment of measurement. The letter that matters most for
troubleshooting is Z (zombie): it signals a finished process that its
parent has not collected. The lower-case letters and symbols that follow an
upper-case one are details, not states of their own.
| Letter | Meaning |
|---|---|
S | Sleeping (waiting for an event) |
R | Running |
D | Waiting for a disk or network operation, uninterruptible: a kill has no effect while the wait lasts |
T | Stopped (suspended) |
Z | Zombie (finished but not cleaned up by the parent) |
s (lower case) | Session leader |
+ | In the terminal's foreground |
How do you watch processes with top?
top shows processes in real time, refreshed every
few seconds:
toptop - 10:30:00 up 2:30, 1 user, load average: 0.15, 0.10, 0.05Tasks: 142 total, 1 running, 141 sleeping, 0 stopped, 0 zombie%Cpu(s): 2.3 us, 1.0 sy, 0.0 ni, 96.5 id, 0.2 wa, 0.0 hi, 0.0 siMiB Mem : 7953.4 total, 5120.2 free, 1580.6 used, 1252.6 buff/cacheThe essential information at the top:
| Field | Meaning |
|---|---|
up 2:30 | The system has been running for 2h30 |
load average | Average load (1 min, 5 min, 15 min) |
Tasks | Total number of processes and their states |
%Cpu | Breakdown of CPU use |
MiB Mem | Memory use |
Shortcuts in top:
| Key | Action |
|---|---|
q | Quit |
M | Sort by memory |
P | Sort by CPU |
k | Send a signal (kill a process) |
h | Help |
How do the foreground and background work?
By default, a command runs in the foreground: it blocks the terminal until it finishes.
Start in the background with &
Add & at the end of the command:
sleep 60 &[1] 1400The terminal gives you back control. [1] is the job number and 1400 is
the PID.
See the running jobs
The jobs command lists the tasks started from this terminal, with their
number in brackets. This number is not the PID: it is an identifier local
to the shell (the command interpreter running in your terminal), the one you
will reuse with fg %1 or bg %1. The + marks the default job, the one fg
or bg pick up if you give no number.
jobs[1]+ Running sleep 60 &Suspend a process with Ctrl+Z
If a process runs in the foreground and you want to get control back without stopping it:
-
Press Ctrl+Z: the process is suspended (state
T)[1]+ Stopped sleep 60 -
To resume it in the background:
Terminal window bg -
To bring it back to the foreground:
Terminal window fg
Summary of the job commands
These commands form the full job control cycle: start in the background,
suspend, list, then bring back to the foreground or resume in the background. Keep
in mind that fg and bg with no argument act on the current job, the one
marked +; the %N suffix targets a precise job when several run in parallel.
| Command | Action |
|---|---|
command & | Starts in the background |
Ctrl+Z | Suspends the foreground process |
jobs | Lists the terminal's jobs |
fg | Brings the current job back to the foreground |
fg %2 | Brings job number 2 back to the foreground |
bg | Resumes the last suspended job in the background |
This lesson stops at observing and controlling jobs. The next lesson,
Stop a Linux process,
teaches kill and the SIGTERM and SIGKILL signals. Adjusting the priority of
a process (nice, renice, Nice=) is covered in
Manage processes on Linux,
at the Operate level.
Troubleshooting
The situations below are the ones that confuse people most when starting with processes: an output that looks abnormal but is not, or a terminal that seems frozen. Find the symptom in the left column first: the likely cause will keep you from looking in the wrong place.
| Symptom | Likely cause | Fix |
|---|---|---|
ps aux prints hundreds of lines | Normal behaviour on an active system | Filter with ps aux | grep name |
A zombie process (state Z) | The parent process has not collected the exit code | Usually harmless; restart the parent service if it persists |
top uses a lot of CPU | Refresh interval too short | Press d in top and choose a longer interval |
fg: no current job | No suspended process | Check with jobs |
| The terminal no longer responds | A process is blocking the foreground | Try Ctrl+C, then Ctrl+Z if Ctrl+C does not work |
Key points
- A process is a program being run, identified by a PID.
ps auxlists every process,topshows them in real time.&starts in the background, Ctrl+Z suspends,fgandbgswitch.jobsshows the tasks of the current terminal.- The PID 1 process (
init/systemd) is the ancestor of every user-space process.
Knowledge check
Check that the essentials of this guide stuck. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Stop a Linux process
A new full quiz with random questions
Work again only on the questions you missed