Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Understand Linux processes

By updated

Improve this page

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 ps and ps 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

Terminal window
ps
Output
PID TTY TIME CMD
1234 pts/0 00:00:00 bash
1256 pts/0 00:00:00 ps

Everything started elsewhere, services and other sessions included, stays invisible here.

Every process on the system

Terminal window
ps aux
Output (excerpt)
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 169624 13412 ? Ss 08:00 0:01 /sbin/init
root 412 0.0 0.1 32120 8744 ? Ss 08:00 0:00 /usr/sbin/sshd
bob 1234 0.0 0.0 8536 5200 pts/0 Ss 09:15 0:00 -bash
bob 1300 0.5 1.2 245680 98200 pts/0 S+ 10:00 0:03 python3 script.py

Each column has a meaning:

ColumnMeaning
USEROwner of the process
PIDUnique identifier of the process
%CPUPercentage of processor use
%MEMPercentage of memory use
VSZVirtual memory allocated (in KiB)
RSSMemory actually used (in KiB)
TTYAssociated terminal (? = no terminal)
STATState of the process
STARTStart time
TIMECPU time used
COMMANDCommand that started the process

Filter with grep

To look for a specific process:

Terminal window
ps aux | grep sshd
Output
root 412 0.0 0.1 32120 8744 ? Ss 08:00 0:00 /usr/sbin/sshd
bob 1350 0.0 0.0 6420 720 pts/0 S+ 10:05 0:00 grep sshd

Process 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.

LetterMeaning
SSleeping (waiting for an event)
RRunning
DWaiting for a disk or network operation, uninterruptible: a kill has no effect while the wait lasts
TStopped (suspended)
ZZombie (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:

Terminal window
top
Output (header)
top - 10:30:00 up 2:30, 1 user, load average: 0.15, 0.10, 0.05
Tasks: 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 si
MiB Mem : 7953.4 total, 5120.2 free, 1580.6 used, 1252.6 buff/cache

The essential information at the top:

FieldMeaning
up 2:30The system has been running for 2h30
load averageAverage load (1 min, 5 min, 15 min)
TasksTotal number of processes and their states
%CpuBreakdown of CPU use
MiB MemMemory use

Shortcuts in top:

KeyAction
qQuit
MSort by memory
PSort by CPU
kSend a signal (kill a process)
hHelp

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:

Terminal window
sleep 60 &
Output
[1] 1400

The 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.

Terminal window
jobs
Output
[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:

  1. Press Ctrl+Z: the process is suspended (state T)

    [1]+ Stopped sleep 60
  2. To resume it in the background:

    Terminal window
    bg
  3. 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.

CommandAction
command &Starts in the background
Ctrl+ZSuspends the foreground process
jobsLists the terminal's jobs
fgBrings the current job back to the foreground
fg %2Brings job number 2 back to the foreground
bgResumes 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.

SymptomLikely causeFix
ps aux prints hundreds of linesNormal behaviour on an active systemFilter with ps aux | grep name
A zombie process (state Z)The parent process has not collected the exit codeUsually harmless; restart the parent service if it persists
top uses a lot of CPURefresh interval too shortPress d in top and choose a longer interval
fg: no current jobNo suspended processCheck with jobs
The terminal no longer respondsA process is blocking the foregroundTry 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 aux lists every process, top shows them in real time.
  • & starts in the background, Ctrl+Z suspends, fg and bg switch.
  • jobs shows 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

6 questions
6 min
70% to pass

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