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
- A process is a running program, with its own memory, its own owner, and a process ID the kernel gives it.
- ps prints one row per process, as a snapshot of one moment and not a live view.
- Sort by CPU to find the busiest process, and filter by name to narrow a long list.
- The STAT column shows the state: R is running, S is sleeping, D is waiting for disk, T is stopped, and Z is a zombie.
- Check the process ID before you act, because two copies of one program have two IDs.
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.
ps aux --sort=-%cpu | head -n 5ps -ef | grep reportps -p 1 -o pid,commNote: On Ubuntu 24.04, process ID 1 is systemd, the first process the kernel starts.
The columns that matter
- PID: the process ID. Use it to name one process exactly.
- %CPU: the average share of CPU time since the process started. A short burst can be hidden inside that average.
- STAT: the state letters. R is running, S is sleeping, D is waiting for disk, T is stopped, and Z is a zombie, a process that has ended but is not yet cleared.
- COMMAND: the program name and the arguments it was started with. It is often the fastest way to tell two processes apart.
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.
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 5What you should see: The first row is the header, and the rows below are the busiest processes.
List the processes in the classic style, and keep only the lines that mention report.
ps -ef | grep reportShow process ID 1 and its program name.
ps -p 1 -o pid,commWhat 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.