System and processes
The top command
Real-time process monitor: shows the load, memory and the processes using the most CPU or memory, updating on its own. Press q to quit.
Most useful options
-bBatch mode: prints and exits, with no interactive screen. Useful for scripts and files-n <veces>Number of updates before it exits (with -b)-d <segundos>Seconds between updates-o <campo>Sorts by a field, for example %MEM or %CPU-p <pid>Shows only the given PIDs-u <usuario>Shows only the processes of that user-HShows individual threads instead of summing them per process-cShows the full command line of each process-1Shows CPU core by core, instead of the average-w <columnas>Output width. Useful in batch modeCopy-ready examples
$ topinteractive monitor. q to quit and k to send a signal to a process.$ top -b -n 1 | head -n 12a text snapshot of the state, to save it or pass it to another program.Example output
top - 10:21:37 up 3 days, 4:12, 1 user, load average: 0.52, 0.48, 0.41
Tasks: 287 total, 1 running, 286 sleeping, 0 stopped, 0 zombie
%Cpu(s): 4.2 us, 1.1 sy, 0.0 ni, 94.5 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 15898.4 total, 3120.5 free, 6234.1 used, 6543.8 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 9216.3 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2231 miguel 20 0 4520112 512380 128904 S 6.3 3.2 4:12.07 code$ top -b -n 1 -o %MEM | head -n 8the processes sorted by memory, from highest to lowest.$ top -d 5 -p 2231follows a single process and updates every 5 seconds.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| No error message | Without -b, top draws the screen with control codes. When saved to a file, those codes stay inside it. | Use top -b -n 1 > status.txt to save a clean text snapshot. |
| No error message | The PID given with -p does not exist, or the process has already finished. | Check the PID with ps -p PID or with pgrep. |
Typical mistakes
- Here it is a simulated, fixed view; on a real Linux it refreshes itself and you quit with q.
- A CPU at 100% is not bad by itself: check whether there are processes in state R (running).
Differences from similar commands
Security
In top, the k key asks for the PID and the signal and then sends it. Check the process name before confirming: killing a service by mistake takes it down. If top is shared on screen, it also shows the full command line of the processes.
FAQ
What is the difference between top and htop?
htop is more comfortable, with colors, scrolling and menus, but it is not installed by default on every system. top is on almost all of them.
Why does CPU go above 100 %?
On multicore systems each thread can reach 100 %. A process with four busy threads shows 400 %.
How do I save the output of top?
With top -b -n 1 > status.txt you take a text snapshot. For a series of snapshots, use -n with the number of samples you want.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course