top-command-in-linux-to-display-the-the-process

How to use top command in Linux step by step guide for beginners

The top command in Linux is one of the most frequently used commands in our daily system administrative jobs. If you are looking for your career as a system administrator you must know about the top command.

Top command is used to show the linux processes. You can view the real time running system. You can see the processor activity and view real-time task managed by kernel. You can use neccesary action to stop, kill any unwanted process.

When you will run this command, it will will open an interactive command mode where the top half portion will contain the statistics of processes and resource usage. And other/lower half contains a list of the currently running processes.

If you want to exit from command mode simply press “q” key from your keyboard.

How to use the top command in Linux

Open terminal by pressing the combination of Ctrl+Alt+t and type “top”, as well as you hit enter, you will enter in top command mode.

Press “q” when you want to exit from this mode.

Here,

  • PID: Shows the task’s unique process id.
  • PR: Stands for the priority of the task.
  • SHR: Represents the amount of shared memory used by a task.
  • VIRT: Total virtual memory used by the task.
  • USER: User name of the owner of the task.
  • %CPU: Represents the CPU usage.
  • TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.
  • SHR: Represents the Shared Memory size (kb) used by a task.
  • NI: Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.
  • %MEM: Shows the Memory usage of a task.

Display Specific user process

If you want to monitor processes related specific user then use top command followed by -u and username. They syntax will be as below:

$top -u [username]

For Example I want to display processes of vijay user then the syntax will be as follows:

$top -u vijay

See the results as follows:

Highlight Running Process in Top:

You can press the ‘z‘ option to display top running processes in color which may help you to identify the running process easily.

Shows Absolute Path of Processes:

As you know every process has a specific location. If you want to display the absolute running process then press ‘c‘ key on your keyboard and see the absolute path of the running process.

Sort Processes by CPU Utilization:

Every running process utilize some part of the CPU. Those processes may utilize process less or more.

If you want to short processes according to CPU utilization then press (Shift+P) to sort processes.

See the example below:

Kill the running process within top command

You can kill a process after finding PID of process by pressing ‘k‘ option.

I want to kill process number 2567 then I will press ‘k” key, and give the PID number. as you hit enter the process will be killed of same PID

Save Top Command Results:

To save the running top command results output to a file /root/.toprc use the following command.

Change Delay or Set ‘Screen Refresh Interval’ in Top

By default screen refresh interval is 3.0 seconds, same can be change pressing ‘d‘ option in running top command and change it as desired as shown below.

Getting top command help:

use top command followed by -h option to display the help

[[email protected] ~]$ top -h
  procps-ng 3.3.15
Usage:
  top -hv | -bcEHiOSs1 -d secs -n max -u|U user -p pid(s) -o field -w [cols]
[[email protected] ~]$ 

Conclusion

You have learned about top command in Linux, which is used to display processes in the Linux and Unix system and server. For more details about top command please visit the manual page here

If you have any questions or feedback, feel free to leave a comment.

Special Offer on Ethical hacking Course in Hindi

Ethical-hacking-course-in-hindi-50-off

If Appreciate My Work, You should consider: