{"id":5331,"date":"2018-07-10T13:10:43","date_gmt":"2018-07-10T09:10:43","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-top-command\/"},"modified":"2018-07-10T13:10:43","modified_gmt":"2018-07-10T09:10:43","slug":"linux-top-command-tutorial-for-beginners-8-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-top-command-tutorial-for-beginners-8-examples\/","title":{"rendered":"Linux top Command Tutorial for Beginners (8 Examples)"},"content":{"rendered":"<p>While working on the Linux command line, there may be times when you&#8217;d want to check process related details, like which process is consuming CPU or memory the most? Well, there exists a command &#8211; dubbed top &#8211; that lets you do this easily. In this tutorial, we will discuss this tool using some easy to understand examples.<\/p>\n<p>But before we do that, it&#8217;s worth mentioning that all examples mentioned in this article have been tested on an Ubuntu 16.04 LTS machine.<\/p>\n<h2 id=\"linux-top-command\">Linux top command<\/h2>\n<p>The top command displays a list of processes or threads currently being managed by the Linux kernel, along with useful information related to them. Following is the tool&#8217;s syntax:<\/p>\n<p class=\"command\">top [options]<\/p>\n<p>And here&#8217;s what the tool&#8217;s man page says about it:<\/p>\n<pre readability=\"7\"> The\u00a0 top\u00a0 program\u00a0 provides\u00a0 a dynamic real-time view of a running<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 system.\u00a0 It can display system summary information as\u00a0 well\u00a0 as\u00a0 a<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list\u00a0 of processes or threads currently being managed by the Linux<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 kernel.\u00a0 The types of system summary\u00a0 information\u00a0 shown\u00a0 and\u00a0 the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 types,\u00a0 order\u00a0 and size of information displayed for processes are<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 all user configurable and that configuration can be\u00a0 made\u00a0 persis?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tent across restarts.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The\u00a0 program\u00a0 provides a limited interactive interface for process<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 manipulation as well as a much more extensive interface\u00a0 for\u00a0 per?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sonal\u00a0 configuration\u00a0\u00a0 --\u00a0 encompassing every aspect of its opera?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tion.<\/p><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the top command works.<\/p>\n<h2 id=\"q-how-to-use-top\">Q1. How to use top?<\/h2>\n<p>Simple, just execute the &#8216;top&#8217; command sans any option:<\/p>\n<p class=\"command\">top<\/p>\n<p>Here&#8217;s the output it produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-top-output-basic\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/top-output-basic.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples.png\" alt=\"How to use top command\" width=\"500\" height=\"285\" title=\"\"><\/a><\/p>\n<p>Note that what you see in the screenshot is just a snapshot of the real-time output (which changes after a fixed interval) that was produced.<\/p>\n<h2 id=\"q-how-to-understand-top-command-output\">Q2. How to understand top command output?<\/h2>\n<p>Let&#8217;s start with the first line. It contains entries for (in that order), current time, duration since the system is up and running, active user sessions, and average load on the system (for last one minute, five minutes, and fifteen minutes, respectively).<\/p>\n<p>The second line contains information (in that order) about total number processes, number of running processes, number of sleeping processes, number of processes that have stopped, and number of processes in the zombie state.<\/p>\n<p>The third line contains CPU-usage information. Following are the details:<\/p>\n<pre> us, user\u00a0\u00a0\u00a0 : time running un-niced user processes<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sy, system\u00a0 : time running kernel processes<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ni, nice\u00a0\u00a0\u00a0 : time running niced user processes<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id, idle\u00a0\u00a0\u00a0 : time spent in the kernel idle handler<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 wa, IO-wait : time waiting for I\/O completion<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 hi : time spent servicing hardware interrupts<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 si : time spent servicing software interrupts<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 st : time stolen from this vm by the hypervisor <\/pre>\n<p>The next two lines show information related to RAM and swap memory usage. And finally, comes processes related information, which consists of (in that order) process ID, user who owns the process, priority of the process, nice value of the process, virtual, physical, and shared memory used by the process, process status (Sleeping, Running, or Zombie), CPU and RAM usage, time of activity, and command that initiated the process.<\/p>\n<h2 id=\"q-how-to-kill-a-process-from-within-top-output\">Q3. How to kill a process from within top output?<\/h2>\n<p>This is pretty simple &#8211; just press &#8216;k&#8217; and top will ask you for the PID of the process you want to kill. You&#8217;ll see a message similar to the following appearing just above the line containing process column headers:<\/p>\n<pre>PID to signal\/kill [default pid = 3397]<\/pre>\n<p><a class=\"fancybox\" id=\"img-top-kill\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/top-kill.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples-1.png\" alt=\"How to kill a process from within top output\" width=\"500\" height=\"102\" title=\"\"><\/a><\/p>\n<p>So you see, you can either enter the process ID or by default, top will try killing (by sending SIGTERM) the first process in the list. Once the signal is sent, a message similar to the following is produced.<\/p>\n<pre>Send pid 3007 signal [15\/sigterm]<\/pre>\n<h2 id=\"q-how-to-change-priority-of-a-process\">Q4. How to change priority of a process?<\/h2>\n<p>Like &#8216;k&#8217; is for killing, you can press &#8216;r&#8217; in case you want to change the priority of a process (or you want to renice it). Pressing &#8216;r&#8217; produces a message similar to the following:<\/p>\n<pre>PID to renice [default pid = 3397] <\/pre>\n<p>So either enter a PID or top will try renicing the priority of the first process in list by default. For example, I passed a PID, and then top asked me for the new nice value.<\/p>\n<pre>Renice PID 2665 to value<\/pre>\n<p>Just provide a value, and press enter, and you&#8217;ll see the nice value for the process in question will get changed.<\/p>\n<h2 id=\"q-how-to-change-refresh-rate-of-top-command\">Q5. How to change refresh rate of top command?<\/h2>\n<p>By default, top refreshes the output after every 3 seconds, but you can tweak this by pressing &#8216;d&#8217;. The command will ask you to enter the new delay value:<\/p>\n<pre>Change delay from 3.0 to <\/pre>\n<p>Just enter the value, and press enter. That&#8217;s it.<\/p>\n<h2 id=\"q-how-to-limit-top-command-output-to-a-user\">Q6. How to limit top command output to a user?<\/h2>\n<p>By default, top command displays all processes. However, you can limit the output to a particular user by pressing &#8216;u&#8217;.<\/p>\n<pre>Which user (blank for all)<\/pre>\n<p>Just enter the user name in the line above, and press enter, and you&#8217;ll see the output will contain only those processes that are owned by the user whose name you entered.<\/p>\n<p>For example, I entered &#8216;root&#8217;, and here&#8217;s the output:<\/p>\n<p><a class=\"fancybox\" id=\"img-top-root\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/top-root.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples-2.png\" alt=\"How to limit top command output to a user\" width=\"500\" height=\"280\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-top-display-complete-command-along-with-arguments\">Q7. How to make top display complete command along with arguments?<\/h2>\n<p>This can be done by pressing &#8216;c&#8217;.\u00a0 Here&#8217;s an example:<\/p>\n<p><a class=\"fancybox\" id=\"img-top-c-press\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/top-c-press.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples-3.png\" alt=\"How to make top display complete command along with arguments\" width=\"500\" height=\"89\" title=\"\"><\/a><\/p>\n<p>So you can see complete command path as well as command line arguments in the output now.<\/p>\n<h2 id=\"q-how-to-get-help-with-interactive-top-commands\">Q8. How to get help with interactive top commands?<\/h2>\n<p>To get help related to interactive top commands, press &#8216;h&#8217;. In the output you&#8217;ll see available commands, and what they do. For example, here&#8217;s what popped up on my system when I pressed &#8216;h&#8217;.<\/p>\n<p><a class=\"fancybox\" id=\"img-top-help\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/top-help.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples-4.png\" alt=\"How to get help with interactive top commands\" width=\"500\" height=\"289\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>We&#8217;ve just scratched the surface here. The top command provides a lot more features. Once you have understood what all we&#8217;ve discussed in this article, and are done practicing it, head to the top&#8217;s\u00a0<a href=\"https:\/\/linux.die.net\/man\/1\/top\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a> to learn more about it.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-top-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-top-command%2F&amp;text=Linux+top+Command+Tutorial+for+Beginners+%288+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples-7.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-top-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-top-command-tutorial-for-beginners-8-examples-8.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>While working on the Linux command line, there may be times when you&#8217;d want to check process related details, like which process is consuming CPU or memory the most? Well, there exists a command &#8211; dubbed top &#8211; that lets you do this easily. In this tutorial, we will discuss this tool using some easy &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-5331","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=5331"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5331\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=5331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=5331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=5331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}