How to use TOP command in Linux with examples

it Linux top command provided real time analysis of process or tasks being handled by kernel. It shows processor utilization. Basically it gives overview of running application, which is helpful in analyzing running processes and sometimes in taking corrective action.

Syntax

top

It will display all information (running task, cpu and memory utilization). To quit top press q and you will quit top application. Information displayed by top is detailed below

  1. PID is process id which is unique to each process
  2. User is owner of process running, user name is displayed.
  3. PR is priority of a process its basically 20+ Nice value. If RT is displayed it means process is running in real time.
  4. NI is nice value it can be any value between -20 to 19. The higher is the value lower is its priority. If 19 is nice value of program, it is of lowest priority and it will be executed whenever cpu gets time.
  5. VIRT is virtual memory used by process.
  6. RES is how much resident or non swapped memory utilized by process.
  7. SHR is shared memory used by process. Shared memory is virtual memory (VIR) is shareable.
  8. S is process status. It can be D (uninterruptible sleep), R (Running), S (Sleeping), T( traced or stopped), Z (Zombie)
  9. %CPU  Its CPU utilized by process since last update, it shows value of single CPU utilization and if you have multi core cpu it can go above 100.
  10. %Memory is percentage of physical memory used by process.
  11. Time is CPU time used by process post its execution
  12. Command is the command which started process.

Display running process with Highlighted colors

On TOP command terminal press ‘z’ to highlight running processes with colors.

Display processes executed by specific user

To display processes executed by specific user, use top command with -u switch followed by username.

Syntax

top -u [username]

Example

top -u root

Kill process by using top command

Another interesting usage of top command is to kill a process. To Kill a process press ‘k’ on top terminal, after press ‘k’ you will be asked for PID number of command. Entering PID will kill that process.

Display path of process

To display path of processes enter c on top window. Now path of process will be displayed.

Sort output of top command

To sort output of top command you will have to use -O (capital letter).

Syntax

top -O

you will be presented by a list on which sorting can be done. Each sort able parameter is donated by a letter, on pressing this letter you will sort on the parameter.

Change default screen refresh

Default screen refresh interval is 3 seconds. To change this delay press ‘d’ in top terminal and provide the value you want to change to.