{"id":13584,"date":"2019-04-03T11:11:47","date_gmt":"2019-04-03T11:11:47","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13584"},"modified":"2019-04-03T11:11:47","modified_gmt":"2019-04-03T11:11:47","slug":"find-top-15-processes-by-memory-usage-with-top-in-batch-mode","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/find-top-15-processes-by-memory-usage-with-top-in-batch-mode\/","title":{"rendered":"Find Top 15 Processes by Memory Usage with \u2018top\u2019 in Batch Mode"},"content":{"rendered":"<p>Similarly to the previous tip about\u00a0<a href=\"https:\/\/www.tecmint.com\/find-linux-processes-memory-ram-cpu-usage\/\" target=\"_blank\" rel=\"noopener\">find out top processes by RAM and CPU usage<\/a>, you can also use\u00a0<a href=\"https:\/\/www.tecmint.com\/12-top-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">top command<\/a>\u00a0to view the same information. Perhaps there\u2019s an extra advantage of this approach when compared to the previous one: the\u00a0<strong>\u201cheader\u201d<\/strong>\u00a0of top provides extra information about the current status and usage of the system: the uptime, load average, and total number of processes, to name a few examples.<\/p>\n<div id=\"attachment_21859\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/07\/Find-Processes-By-Memory-Usage-with-top.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-21859\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/07\/Find-Processes-By-Memory-Usage-with-top.png\" alt=\"Find Processes By Memory Usage with top\" width=\"720\" height=\"345\" aria-describedby=\"caption-attachment-21859\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-21859\" class=\"wp-caption-text\">Find Processes By Memory Usage with top<\/p>\n<\/div>\n<p>To display the top 15 processes sorted by memory use in descending order, do:<\/p>\n<pre># top -b -o +%MEM | head -n 22\r\n<\/pre>\n<p>As opposed to the previous tip, here you have to use\u00a0<code>+%MEM<\/code>\u00a0(note the plus sign) to sort the output in descending order:<\/p>\n<div id=\"attachment_21856\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/07\/List-Top-15-Processes-By-Memory-Usage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-21856\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/07\/List-Top-15-Processes-By-Memory-Usage.png\" alt=\"List Top 15 Processes By Memory Usage\" width=\"638\" height=\"408\" aria-describedby=\"caption-attachment-21856\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-21856\" class=\"wp-caption-text\">List Top 15 Processes By Memory Usage<\/p>\n<\/div>\n<p>From the command above, the option:<\/p>\n<ol>\n<li><code>-b<\/code>\u00a0: runs top in batch mode<\/li>\n<li><code>-o<\/code>\u00a0: used to specify fields for sorting processes<\/li>\n<li><code>head<\/code>\u00a0utility displays the first few lines of a file and<\/li>\n<li>the\u00a0<code>-n<\/code>\u00a0option is used to specify the number of lines to be displayed.<\/li>\n<\/ol>\n<p><strong>Note<\/strong>\u00a0that\u00a0<strong>head<\/strong>\u00a0utility, by default displays the first ten lines of a file, that is when you do not specify the number of lines to be displayed. Therefore, in the example above, we displayed the first 22 lines of\u00a0<a href=\"https:\/\/www.tecmint.com\/12-top-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">top command<\/a>\u00a0output in batch mode.<\/p>\n<h4>Redirect or Save \u2018top\u2019 Output to File in Linux<\/h4>\n<p>Additionally, using\u00a0<strong>top<\/strong>\u00a0in batch mode allows you to redirect the output to a file for later inspection:<\/p>\n<pre># top -b -o +%MEM | head -n 22 &gt; topreport.txt\r\n<\/pre>\n<p>As we have seen, the\u00a0<strong>top<\/strong>\u00a0utility offers us more dynamic information while listing processes on a Linux system, therefore, this approach has an extra advantage compared to using\u00a0<a href=\"https:\/\/www.tecmint.com\/find-linux-processes-memory-ram-cpu-usage\/\" target=\"_blank\" rel=\"noopener\">ps utility<\/a>\u00a0which we covered in tip one.<\/p>\n<p>But most importantly, you must always run\u00a0<strong>top<\/strong>\u00a0in batch mode to redirect its output to a file or another process. Additionally, if you have any tips regarding use of\u00a0<strong>top<\/strong>, you can also share them with us via the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/find-processes-by-memory-usage-top-batch-mode\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Similarly to the previous tip about\u00a0find out top processes by RAM and CPU usage, you can also use\u00a0top command\u00a0to view the same information. Perhaps there\u2019s an extra advantage of this approach when compared to the previous one: the\u00a0\u201cheader\u201d\u00a0of top provides extra information about the current status and usage of the system: the uptime, load average, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/find-top-15-processes-by-memory-usage-with-top-in-batch-mode\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Find Top 15 Processes by Memory Usage with \u2018top\u2019 in Batch Mode&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13584","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13584"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13584\/revisions"}],"predecessor-version":[{"id":13585,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13584\/revisions\/13585"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}