{"id":4448,"date":"2024-03-23T02:15:00","date_gmt":"2024-03-23T06:15:00","guid":{"rendered":"https:\/\/www.both.org\/?p=4448"},"modified":"2024-03-18T14:35:46","modified_gmt":"2024-03-18T18:35:46","slug":"navigating-the-top-command-in-linux","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=4448","title":{"rendered":"Navigating the \u2018top\u2019 Command in Linux"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"4448\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p class=\"wp-block-paragraph\">When checking out Linux systems (or even troubleshooting computers running other operating systems), I frequently use the top command to check out the system&#8217;s RAM and CPU utilization. It provides me with information to assess the computer&#8217;s overall health. I learned about the top command early in my Linux journey and have relied on it to give me a quick overview of what is happening on servers or other Linux systems, including Raspberry Pi. According to its man page, the top program provides a dynamic real-time view of a running system. It can display system summary information and a list of processes or threads currently <em>managed by the Linux kernel<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I often need A quick overview to determine what is going on with the system in question. But there is so much more to the <code>top<\/code> command than meets the eye. Specific features of your <code>top<\/code> command may vary depending on whose version (procps-ng, Busybox, BSD) you run, so consult the man page for details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To launch <code>top<\/code>, type it into your terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ top<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"807\" height=\"534\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2024\/03\/image-3.png\" alt=\"\" class=\"wp-image-4449\" style=\"width:873px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Running processes are displayed below the table heading on the <code>top<\/code> screen, and system statistics are shown above it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Press the <strong>Z<\/strong> key to change the color of the output. I find this makes the output a little easier on the eyes. Press the <strong>1<\/strong> key to see a graphical representation of each CPU core on the system. Press <strong>1<\/strong> repeatedly to assess core statistics for your CPU cores.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can display memory usage graphically by invoking the <code>top<\/code> command and then pressing the <strong>m<\/strong> key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"useful-top-options\">Useful top options<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re looking only for the processes started by a specific user, you can get that information with the <code>-u<\/code> option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ top -u 'username'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To get a list of idle processes on your system, use the <code>-i<\/code> option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ top -i<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can set the update interval to an arbitrary value in seconds. The default value is three seconds. Change it to five like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ top -d 5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also run <code>top<\/code> on a timer. For instance, the following command sets the number of iterations to two and then exits:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ top -n 2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"locate-a-process-with-top\">Locate a process with top<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Press <strong>Shift+L<\/strong> to locate a process by name. This creates a prompt just above the bold table header line. Type in the name of the process you&#8217;re looking for and then press <strong>Enter<\/strong> or <strong>Return<\/strong> to see the instances of that process highlighted in the newly sorted process list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stopping-a-process-with-top\">Stopping a process with top<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can stop or &#8220;kill&#8221; a running process with, too. First, find the process you want to stop using either <strong>Shift+L<\/strong> or <code>pgrep<\/code>. Next, press <strong>K<\/strong> and enter the process ID you want to stop. The default value is whatever is at the top of the list, so be sure to enter the PID you want to stop before pressing <strong>Enter<\/strong>, or you may stop a process you didn&#8217;t intend to.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/opensource.com\/sites\/default\/files\/2022-03\/top-results_0.png\" alt=\"top results\" style=\"width:920px;height:auto\"\/><figcaption class=\"wp-element-caption\">Image by: (Don Watkins, CC BY-SA 4.0)<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"top-top\">Top top<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are many iterations of the <code>top<\/code> command, including <code>htop<\/code>, <code>atop<\/code>, <code>btop<\/code>, and <code>ttop<\/code>. There are specialized <code>top<\/code> commands, too, like <code>powertop<\/code> for power usage and <code>ntop<\/code> for networks. What&#8217;s your favorite <code>top<\/code>?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When checking out Linux systems (or even troubleshooting computers running other operating systems), the top command provides information to assess the computer&#8217;s overall health. <\/p>\n<p>It can give a quick overview of what is happening on servers or other Linux systems, including Raspberry Pi with a dynamic real-time view of a running system. But there is so much more to the top command than meets the eye.<\/p>\n","protected":false},"author":32,"featured_media":4452,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[100,5,89],"tags":[282],"class_list":["post-4448","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-linux","category-system-administration","tag-top"],"modified_by":"David Both","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/4448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4448"}],"version-history":[{"count":3,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/4448\/revisions"}],"predecessor-version":[{"id":4455,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/4448\/revisions\/4455"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/4452"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}