Reading the process list with ps

Video 121 of 140 in Virtualization Foundations, in the unit “Processes, signals, /proc and /sys”. 4:04, with English and Hindi audio.

Every program that runs on a Linux machine is a process. When a server feels slow, the first question is which process is using the CPU. The ps command answers it with a list of running processes, one row each, showing who owns each one, its process ID, and how much CPU and memory it uses. This article explains what a process is, how to sort and filter the list with ps, how to read each column, and three traps that catch people who read the output too quickly.

What you will learn

Every running program is a process

A process is a running program. It has its own memory, its own owner, and a number that names it, called a process ID. The kernel, which is the core of Linux, creates a process and keeps track of it until it ends.

Picture a warehouse application server that suddenly feels slow. Dozens of programs run on it, and most of them are quiet. Someone has to find the one program that is busy, and the process list is where that search starts.

Listing and filtering processes with ps

The ps command asks the kernel for its table of running processes. Options tell it which columns to print. It prints one row for each process, and the rows show one moment in time.

Show the header and the four busiest processes, highest CPU share first
ps aux --sort=-%cpu | head -n 5
List every process in the classic style, then keep only lines that mention report
ps -ef | grep report
Show process ID 1 and its program name
ps -p 1 -o pid,comm

Note: On Ubuntu 24.04, process ID 1 is systemd, the first process the kernel starts.

The columns that matter

Three traps when reading the list

The first trap is treating the output as a live view. It is a snapshot, so a spike that ended a minute ago is gone. The second trap is the length of the list. A busy server has hundreds of rows, so sort it or filter it by name to make the busy process easy to see.

The third trap is two copies of one program. Each copy has its own process ID. Always check the ID before you act, because a command aimed at the wrong copy hits the wrong process.

Try it yourself

You need a Linux terminal. Sort the list to find the busiest processes, filter it by a name, and then ask for one process by its ID.

  1. Show the header and the four busiest processes. The header is the first row, and the highest CPU share is at the top.

    ps aux --sort=-%cpu | head -n 5

    What you should see: The first row is the header, and the rows below are the busiest processes.

  2. List the processes in the classic style, and keep only the lines that mention report.

    ps -ef | grep report
  3. Show process ID 1 and its program name.

    ps -p 1 -o pid,comm

    What you should see: The shell prints the header and the row for process ID 1, which is systemd on Ubuntu 24.04.

Terms

Process
A running program, with its own memory, owner and process ID that the kernel gives it.
Process ID (PID)
The number that names one process exactly, and that you use whenever you want to act on it.

Check yourself

Why does ps not show a CPU spike that happened a minute ago?

ps prints a snapshot of one moment, not a live view. A spike that has ended is no longer in the output.

Which column tells you that a process is a zombie?

STAT. The letter Z means zombie, a process that has ended but is not yet cleared.

What should you check before acting on a process?

Its process ID. Two copies of one program have two IDs, and the name alone can point at the wrong one.

Previous: Diagnosing permission denied. Next: Watching live load with top and htop.