Linux commands: top

By

Published · Updated

Tagged: CLI

Learn how the Linux top command shows running processes in real time, with live CPU, memory, and system load, and how to sort them by memory use with top -o on Linux and macOS.

A quick guide to the top command, used to list the processes running in real time

The top command is used to display dynamic real-time information about running processes in the system.

It’s really handy to understand what is going on.

Its usage is simple, you just type top, and the terminal will be fully immersed in this new view:

Terminal window showing top command output with system stats and process list sorted by CPU usage

The process is long-running. To quit, you can type the q letter or ctrl-C.

The first line has the load average: three numbers, for the last 1, 5 and 15 minutes. That is the average number of processes that want the CPU. On a 4-core machine, 4.00 means the CPUs are fully busy. Above that, work is queuing.

Then you get a memory line (used vs free, plus swap) and the process table. The columns you look at first are PID, %CPU, %MEM and COMMAND.

On Linux, press k and type a PID to send that process a signal. The default is 15 (TERM). h shows the other keys.

Below, the list of processes taking the most memory and CPU is constantly updated.

By default, as you can see from the %CPU column highlighted, they are sorted by the CPU used.

On macOS you sort by memory with:

top -o mem

On Linux (and WSL), procps-ng top wants the field name:

top -o %MEM

You can also press Shift+M inside top on Linux to sort by memory. Shift+P goes back to CPU.

top is the live view. ps lists processes once. kill stops one.

This command works on Linux, macOS, WSL, and anywhere you have a UNIX environment

Want me to talk about your product? You can sponsor this site.

Related posts about cli: