Unbelievable ! 30 Linux TOP Command Examples With Screenshots

November 28, 2013 | By
| 7 Replies More

The top command in Linux displays the running processes on the system. One of the most important tools for a system administrator. It is used extensively for monitoring the load on a server. In this article, we explore the top command in detail. The top command is an interactive command. Many commands are available when top is running. We will explore these commands as well.

1. Top Command output:

First of all, let us understand what the output says. Top command displays a lot of information about the running system. But we need to under stand the meaning of different sections of this output:
Running by default, the top command displays output like this:

Top default display

First few lines are horizontal showing summary about different system parameters, and following these are the processes and their attributes in columns.

1.1 Uptime and Load Averages:

Uptime display

At the top of top command is displayed the output similar to uptime command.

The fields display:
* current time
* the time your system is been up
* number of users logged in
* load average of 5, 10 and 15 minutes respectively.
This uptime display can be toggled with 'l' command.

1.2 Tasks:

Task summary

The second line shows summary of tasks or processes. The processes can be in different states. It shows total number of the processes. Out of these, the processes can be running, sleeping, stopped or in zombie (zombie is the state of a process state, These process summary can be toggled with 't' command.

1.3 CPU States:

CPU status display

Next is shown the CPU state. Here, %age of CPU time in different modes is shown. The meaning of different CPU times are:

* us, user: CPU time in running (un-niced) user processes
* sy, system: CPU time in running kernel processes
* ni, niced: CPU time in running niced user processes
* wa, IO wait: CPU time waiting for IO completion
* hi: CPU time serving hardware interrupts
* si: CPU time serving software interrupts
* st: CPU time stolen for this vm by the hipervisor.

This can be toggled with 't' command.

1.4 Memory Usage:

Memory usage

Next two lines show memory usage, somewhat like 'free' command. 1st of these lines is for physical memory and the second for virtual memory (swap space).
The physical memory is displayed as: total available memory, used memory, free memory, and memory used for buffers
Similarly, swap reflects: total, used, free and cached swap space.
The memory can be toggled with 'm' command.

1.5 Fields/Columns:

Top columns

After these horizontal system properties and states, the processes are shown in columns. The different columns represent different properties discussed below.
By default, top shows these attributes associated with processes:

The Process ID, to uniquely identify a processes.

The effective user name of the owner of the processes.

The scheduling priority of the process. Some values in this field are 'rt'. It means that the process is running under real-time.

The nice value of the process. Lower values mean higher priority.

The amount of virtual memory used by the process.

The resident memory size. Resident memory is the amount of non-swapped physical memory a task is using.

SHR is the shared memory used by the process.

This is the process status. It can have one of the following values:

D - uninterruptible sleep
R - running
S - sleeping
T - traced or stopped
Z - zombie

It is the percentage of CPU time the task has used since last update.

Percentage of available physical memory used by the process.

The total CPU time the task has used since it started, with precision upto hundredth of a second.

The command which was used to start the process.

There are many other outputs which are not displayed by default which can display information about page faults, effective group and group ID of the process, and many more.

2. Interactive Commands:

We discussed earlier that the top command is interactive commands. Some of the commands we encountered in the last section. Here we explore these commands further.

2.1 'h': Help

First of all, you can press 'h' or '?' to display the help menu for interactive commands.

Help options

2.2 '<ENTER>' or '<SPACE>': Refresh Display

The top command by default refreshes after a certain interval (3 seconds). To refresh manually, user can press enter or space key.

2.3 A: Toggle Alternate Display Mode

This command switches between full-screen Mode and alternate-display mode. In alternate display mode, 4 windows are available:
1. Def
2. Job
3. Mem
4. Usr
Each of the 4 field groups has a unique separately configurable summary area and its own configurable task area. Only one of these 4 windows will be the current window. The current window is displayed on the top left corner.

Alternative display mode

You can switch between 4 windows with 'a' and 'w' keys. 'a' moves to next and 'w' to previous window. With 'g' command, you can enter a number to select the current window.

Window selection in alternative display

2.4 B: Toggle Bold Display

Some important information is shown in bold characters. This command toggles use of bold.

Bold off

2.5 'd' or 's': Set Display Time interval

When 'd' or 's' is pressed, you will be prompted to enter a value ( in seconds ) which will be set as display interval. If you enter 1 here, top will refresh every second.

Display time interval

2.6 'l', 't', 'm': Toggle Load, Task, Memory Info

These will toggle load average, task/cpu status and mem info respectively as discussed.

Load average off

CPU summary off

Memory and swap usage off

All three displays off

2.7 'f': Field Management

This is used to chose what field you want to display on the output screen. The fields marked as * are selected.

Managing columns

'<' and '>'
The '<' command moves the sorted field to the left and '>' to the right

2.8 'R': Reverse Sort

Toggle Reverse/Normal sort order

2.9 'c': Toggle Command

Toggle full path of command that started the process and program name.

Full command path

2.10 'i': Idle Tasks

Toggle idle tasks.

Idle task display off

2.11 'V': Forest View

Toggle forest view mode.

Forest view of tasks

2.12 'Z': Change color map

Pressing the 'Z' key takes the user to a screen where the display color can be changed for top command. There are 8 task areas to chose from and 8 colors.

Customizing colors

The below screen shows full colored top view with all 4 screens on.

Colored display

2.13 'z': Toggle Color

Toggle color, i.e. turn on or off the colored display.

2.14 'x' or 'y'

Toggle highlights: 'x' sort field; 'y' running tasks. Depending upon your display settings, You might have to make the output colored in order to notice these highlights.

X and Y highlighted

2.15 'u': Processes of a User

Show processes for a particular user. You are prompted to enter the username. Blank will show for all users.

Processes of 'raghu' user

2.16 'n' or '#': Number of tasks

Set maximum number of tasks displayed.

Setting number of tasks displayed

2.17 'k': Kill tasks

One of the most important commands of top. Used to send signals to tasks (Usually kill tasks).

Killing a task

2.18 'r': Renice

Renice a task to change the scheduling priority.

3. Command line options:

Most of these command line options are similar to the commands discussed above. Top output can be manipulated interactively with commands. But you can start top with some parameters set to your convenience with these options.

3.1 -b: Batch mode

The -b option starts top command in batch mode. It can be useful when you want to save the output in a file.

3.2 -c: Command/Program-name toggle:

As discussed in the above commands, this option will toggle from the last remembered state of command/program name display.

3.3 -d: Set delay interval

Set the delay interval for top (in seconds). For example:

$ top -d 1

will start the top command with 1 sec delay interval.

3.4 -i: idle process toggle

This option sets the top command with last remembered 'i' state reversed.

3.5 -n: Set number of iterations

With -n option, you can set the number of iterations after which top willl end.

$ top -n 3

will exit top automatically after 3 outputs.

3.6 -p: monitor specific PIDs

You can specify what PIDs you want to monitor with -p option. PID value 0 will be treated as process ID of top command itself.

3.7 -u or -U: username or UID

The process of a particular user can be viewed with these options. Username or UID can be specified to the option. The -p, -u and -U options are mutually exclusive. Only one of the options can be used at a time. You get error when you try to use any combination of these options:

$ top -p 28453 -u raghu
top: conflicting process selections (U/p/u)


Free Linux Ebook to Download

Comments (7)

Trackback URL | Comments RSS Feed

  1. shaffooo says:

    Great article. I learnt a lot from this.
    I have a question though. Can we show particular columns in Linux from command line, the way we show them in mac using -stats pid, res, ...


    • Bobbin Zachariah says:

      Hey Shafoo,

      Two option you have (output from centos)

      1)pass values using awk


      top -b -n 1 | awk '{print $1,$2,$NF}'

      2) press "f" and it will list all avalable column names. You can deselect the columns which you dont want by pressing respective keys.

      Example of output

      top - 17:06:20 up 43 days, 17:58, 1 user, load average: 0.00, 0.01, 0.05
      Tasks: 81 total, 0 running, 0 sleeping, 0 stopped, 0 zombie
      Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
      Mem: 1012912k total, 749008k used, 263904k free, 14772k buffers
      Swap: 524284k total, 49964k used, 474320k free, 323908k cached

      PID RES
      1 1072
      2 0
      3 0
      4 0
      5 0
      7 0
      8 0
      9 0
      10 0
      11 0

  2. praveen says:

    good one

  3. James Lewis says:

    Awesome overview. Super helpful, thanks.

  4. ramachandra says:

    Thank you very much for such a super information provided.I learnt a lot.

  5. s.shivasurya says:

    Awesome ! explained well ! thanks

  6. I found this page to be most informative. I was able to customize my environment to my satisfaction.

    Thank you for the fine work!

    (I've been running Linux since the Slackware 1.2 kernel).

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.