Saturday, September 7, 2013

top and htop shell command


Every one knows that Process means program in execution and in Linux everything is works by processes. So it's important to have good knowledge of Process Management/Process Handling. Here Process Management doesn't means that we learned during our academic years in subject called Operating System or Advance Operating System, it means, simply working on process or handling it on Terminal/GNOME-Terminal.
I am writing this blog for those Mind-Hunter's who are crazy to work on Linux Terminal. See, it's simply impossible to know everything in Linux, because Linux has 1000's of Distro for different purpose but still we are crazy to learn new things and that is good.
Now back to main topic, we know that if any one wants to know about process details during execution of Process or simply when Process is running, we always suggest or use top command in terminal. Thats shows following output on terminal.

Fig:- Output of top

In above fig, we can see all processes are running but you can also check a particular process information by using top with it's option -p . But again we have to use top command and have to check for the process ID, instead of doing this you can use pgrep command to know the process ID. Normaly pgrep is use to find the process ID of any process, for this you just have to follow following command.

pgrep 'process name'

Fig:- Output of pgrep

Now to check information of single process using top command follow this command,

top -p 'process_id'

Fig:- Output of top for single process


There are many other options are also available you can try them also. To check documentation of top command typr man top on Gnome-terminal.

Top is a great command to work with runtime processes but I will suggest to use htop command. htop is almost same as top command but htop have some advance facilities for us. htop show cpu, memory and swap usage in better way.

Fig:-Output of htop

You can also modify the look of htop by using it's setup option. To do so type shift+c and you will move to setup , as per your need you can make changes in htop and to exit setup press Esc button. htop have more powerful option you can also try them. To see documentation of htop type man htop. It also have some short cut options that shown below when you use htop(i.e. Function keys).
Fig:- Setup of htop

5 comments:

  1. Ok nice explanation regarding how to use top command and see its options.
    Can you please explain me that is there any option or command through which we can set priority to these processes?

    ReplyDelete
    Replies
    1. We can set the priority of processes using 'nice' and 'renice' commands. You can refer to : http://www.nixtutor.com/linux/changing-priority-on-linux-processes/

      Delete
    2. Thank you for your question Wasif. Okay answer of question is again in htop command, try to install htop and execute it on your terminal and then you find some option at the bottom of htop i.e. function keys for different purpose, okay now use F7 & F8 keys to change the nice value of runtime process, to select process use up & down arrow keys. When you change the nice value of any process, the priority of process automatically get change. You can change nice value of all process only if you are a root user, otherwise you can change nice values of processes of your current account only.

      Delete
  2. "htop" is not available by default in Ubuntu.
    We have to use "sudo apt-get install htop"

    ReplyDelete
    Replies
    1. Thank you so much sir, I forgot to mention it in my blog. :-)

      Delete