← Linux and the Command Line Lesson 25 of 51 · 5 XP

Processes: ps and top

Theory

Machine translation, not yet reviewed by a native speaker.

A process is a running program. Each one has a number, the PID, an owner and a parent (PPID): processes form a tree, with init (PID 1) at the top.

ps is a snapshot of the processes at the current moment:

ps                     # the processes of this terminal
ps aux                 # ALL the processes of the system (BSD style)
ps -ef                 # the same in System V style
ps aux | grep nginx    # find a specific one
pgrep -l python        # the PID by name

The columns of ps aux:

USER the owner
PID the process number
%CPU, %MEM how much processor and memory it uses
VSZ, RSS virtual and real memory in KB
STAT the state: R — running, S — sleeping, Z — zombie, T — stopped
COMMAND the command it was started with

top is a "live" monitor that refreshes every few seconds:

key
P sort by processor
M by memory
k kill a process (it asks for the PID)
q exit

htop is more convenient and nicer: in colour, with mouse support. It's installed with sudo apt install htop.

The first line of top is the load average: the average load over 1, 5 and 15 minutes. A rough rule: if it's greater than the number of processor cores (nproc), the system is overloaded.

Try it yourself: Programmers' Room → Linux · sh.

Sign up for free to mark finished lessons and track your progress.