Technical skill

Linux command: top

Subject: .../LINUX

If a computer suddenly becomes slow, it helps to see which running programs are using the processor or memory. top is a terminal program that refreshes a summary and a list of tasks while you watch. A task is a process or thread being scheduled by Linux. The numbers are samples taken at intervals, so the screen shows what is happening around now rather than a record of the whole day. The columns and their order can be configured.

Run top in a terminal. Press h or ? for help and q to quit. To show a known process, start top -p 1234 with its current PID. In the standard procps-ng interface, P sorts by CPU use and M by memory use. The 1 key toggles individual CPU summary lines on many versions. Use the installed manual or interactive help if the interface differs.

The summary commonly shows uptime, load averages, task counts, CPU time categories, memory, and swap. Load average describes the number of runnable or uninterruptible tasks averaged over time; it is not a CPU percentage. Its significance depends on available CPUs and tasks waiting on resources. Load average covers runnable and uninterruptible tasks across the system, including tasks outside a PID-filtered view. CPU percentages show sampled processor time, while task rows report values attributed to processes or threads.

Memory fields also answer different questions. Virtual size, resident memory, shared memory, and percent of physical memory are not interchangeable. A process's displayed total does not necessarily equal the memory that would be freed when it exits. Check the selected column, accounting method, and whether the view includes individual threads before interpreting a large value.

To investigate a slowdown, note the time and context, sort by CPU or memory, and watch whether the same task stays prominent across several updates. Inspect its command, owner, state, and relevant logs. A thread-level problem may require a thread view or ps -T. For disk or network activity, use a tool that measures that subsystem.

For one noninteractive sample, top -b -n 1 runs in batch mode for a single iteration. Output can vary with configuration, terminal width, locale, and procps-ng version, so avoid treating it as a stable machine-readable interface unless those conditions are controlled. For repeated samples, choose an explicit delay and iteration count and keep the output bounded.

Interactive exercises

Materials

Skillsets
Skillset PostgreSQL DBA preview
image descriptionPostgreSQL DBA
by Artem Naumenko (fb)
1630 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Linux for backend developer preview
image descriptionLinux for backend developer
by Artem Naumenko (fb)
16 users
Skillset Skyeng SRE preview
image descriptionSkyeng SRE
by Yuliya Marochkina
12 users
Skillset Skyeng Senior PlatOps preview
image descriptionSkyeng Senior PlatOps
by Artem Naumenko (slack2)
7 users
Skillset Skyeng linux system administrator preview
image descriptionSkyeng linux system administrator
by Vitaliy Okulov
3 users
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Skillset Skyeng Ops (for DevOps) preview
image descriptionSkyeng Ops (for DevOps)
by Roman Burnashev
2 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful