Linux Real Time System Monitor - Top

Monitoring Linux with top


The top command is a great tool that comes with virtually all distributions of Linux. The top command allows a user or administrator to look at running processes on a system and also identify how much resource is being used by a process. From this tool you can also "kill" processes or renice a process.

Top Monitoring Tool

The first line of the "top" screen shows the current system time and also the length of time that the system has been up (time since system was started). In this example, the system has been up for 13 minutes. Only one user is currently logged onto the system.

System "load averages" are displayed to the immediate right: The load average times indicate the number of runnable processes averaged over the last minute, five minute and fifteen minute intervals. These figures can be used as an indicator to how well your system is handling jobs/processes. If the Load average is high for the last minute and the Load average for the fifteen minute interval is low, then this is an indication that your system is currently handling more work. It doesn't always mean there is an issue. However, if the Load averages are all higher than the number of CPU cores on your system, then you may have a CPU bottleneck. Basically, this means that you may have processes/jobs that are waiting to be processed.

The second line displays information relating to the number of running/sleeping tasks. These can either be running, sleeping, stopped or zombie.

The third line is an indicator of CPU utilisation. These are categorised by "us" for code executing outside of the kernel, "sy" for code executing within the kernel. Although not strictly true, I remember these by "us=user" and "sy"=system". The other headings of "ni" are for processes that have been started with a reduced priority or had the priority changed. The other heading of relevance is "wa". This means processes waiting for I/O. If this value is high, then this can be an indication of a lot of disk activity is currently taking place (reads/writes).

The next two lines are an indication of current memory and its utilisation along with swap file information. These lines provide the same output as the "free" command. The remaining lines are a display of the currently running processes. The "id" of the user running the process and the associated resources used are also displayed.

Press h for help

Whilst this screen is running, you can press "h" for a help screen indicating other options that are available.

Top Monitoring Tool Help

Display all CPUs

If you wish to see how many cpu cores your system has and what each cores utilisation is, press the number "1".

Top Monitoring Tool Cores

From the above, we can see that there are a total of 12 cores on this Linux system.

Killing Processes

An option exists that allows you to kill a process. Great care must be used when selecting the process to kill! To kill a process running, from the main screen view, use the cursor keys to scroll to the process that you want to kill. Now press the letter "k" on your keyboard. The Process ID (PID) will be displayed for you to confirm. In the example, I have selected PID 365436. You will be asked to confirm the process by pressing "enter".

Top Kill Command

The main menu, will confirm the process to be "killed".

Managing Fields

If you wish to change the default view and sort by a different parameter, then you can go to the "field management menu by pressing the letter "f" on your keyboard. Here you can choose which field you want to add or sort by. For example, if you wanted to find out what processes are using your "swap" file (paging), then you can select select "SWAP" by using your cursor keys and then press "s" to use this as a your sortfield, then press escape to return to the main screen.

Top Monitoring Tool Sort

Adding Colour

The main screen colours can be changed easier to highlight certain fields. To access the colour menu, press "SHIFT + Z". From this menu, you can now change the colour scheme. Press the appropriate keys to select which filed you want to change and the number corresponding to the colour you would like to use.

Top Monitoring Tool Colours

Once you have made your changes, you can press "Escape" to return to the main screen. Your new colour scheme should now be showing.

Top Monitoring Tool Colours

Main Column Overview

Below are a list of the default columns that are shown on the top command.

PID -- Process Id

The task's unique process ID, which periodically wraps, though never restarting at zero. In kernel terms, it is a dis-patchable entity defined by a task_struct.

USER -- User Name

The effective user name of the task's owner.

PR -- Priority

The scheduling priority of the task. If you see `rt' in this field, it means the task is running under real time scheduling priority.

NI -- Nice Value

The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in deter mining a task's dispatch-ability.

VIRT -- Virtual Memory Size (KiB)

The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.

RES -- Resident Memory Size (KiB)

A subset of the virtual address space (VIRT) representing the non swapped physical memory a task is currently using.

SHR -- Shared Memory Size (KiB)

A subset of resident memory (RES) that may be used by other processes. It will include shared anonymous pages and shared file backed pages. It also includes private pages mapped to files representing program images and shared libraries.

S -- Process Status

The status of the task which can be one of:
D = uninterruptible sleep
I = idle
R = running
S = sleeping
T = stopped by job control signal
t = stopped by debugger during trace
Z = zombie

%CPU -- CPU Usage

The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.

%MEM -- Memory Usage (RES)

A task's currently resident share of available physical memory.

TIME -- CPU Time

Total CPU time the task has used since it started. When Cumulative mode is On, each process is listed with the cpu time that it and its dead children have used. You toggle Cumulative mode with `S',which is both a command-line option and an interactive command. See the `S' interactive command for additional information regarding this mode.

TIME+ -- CPU Time hundredths

The same as TIME, but reflecting more granularity through hundredths of a second.

COMMAND -- Command Name or Command Line

Display the command line used to start a task or the name of the associated program. You toggle between command line and name with `c', which is both a command-line option and an interactive command.

SWAP -- Swapped Size (KiB)

The formerly resident portion of a task's address space written to the swap file when physical memory becomes over committed.