Find the first 15 processes by memory usage, in batch mode to "top"
Category: Linux command operating system
2016-07-27 00:00:00
Similar to the previous tips on to find out the process by the highest RAM and CPU usage , you can also use the top command to view the same information. There may be a front compared to a additional advantage of this approach: top "head", provides information on the current status and additional information about the system: uptime, load average and total number of processes, to name a few examples.
To sort in descending arrangement of the first 15 processes sorted by memory usage, execute:
# top -b -o +%MEM | head -n 22
Comparison with the previous technique, where you have to use +%MEM
(note plus sign), the output of sort in descending order:
From the above commands, options:
-b
: Top run in batch mode-o
: Designated areas for sorting processhead
Utility displays the first few lines of the file- In
-n
option to specify the number of rows to be displayed.
It should be noted that the first effect, the default file the first ten lines of the display, that is, when you do not specify the number of rows to be displayed. Thus, in the above example, we show that the first 22 rows of the top of the command output in batch mode.
Redirect or save the 'top' output to a file in Linux
Also, in batch mode before , the output is redirected to a file for later examination of:
# top -b -o +%MEM | head -n 22 > topreport.txt
正如我们所看到的, 顶部工具为我们提供而Linux系统上上市进程,因此,这种方法有一个额外的好处相比,使用更多的动态信息PS工具 ,我们覆盖尖之一。
但最重要的,你必须始终之上运行在批处理模式下其输出重定向到文件或其他程序。 此外,如果您有任何关于使用顶部的任何提示,也可以与我们通过下面的反馈表分享。
在Linux中通过Top运行进程查找最高内存和CPU使用率
检查在Linux中按RAM或CPU使用率排序的Top Process
下面的命令将显示由RAM和CPU用在后代的形式(如果你想看到完整的列表中删除的 管道和 头部 )下令top进程的列表:# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
示例输出
PID PPID CMD %MEM %CPU
2591 2113 /usr/lib/firefox/firefox 7.3 43.5 2549 2520 /usr/lib/virtualbox/Virtual 3.4 8.2 2288 1 /home/gacanepa/.dropbox-dis 1.4 0.3 1889 1543 c:\TeamViewer\TeamViewer.ex 1.0 0.2 2113 1801 /usr/bin/cinnamon 0.9 3.5 2254 2252 python /usr/bin/linuxmint/m 0.3 0.0 2245 1801 nautilus -n 0.3 0.1 1645 1595 /usr/bin/X :0 -audit 0 -aut 0.3 2.5
A brief description of the above options used in the above command. The
-o
PS
(or
-format)
option allows you to specify the output format. My favorite is to show the process'
of PID (PID), PPIDs (PID
), and process
(CMD)
related to the executable file (name and RAM and CPU utilization
%mem
and
%cpu
respectively). In addition, I use
--sort
two sort
%mem
or
%cpu
. By default, output will rise in the form of the sort, but I personally like by adding a minus sign in front of the condition to reverse the sorting order. To add other fields output, or change the sort criteria, please refer to the manual pages of
output format control
section
ps
command.
Do not miss: a 15-bit process before find a batch mode by memory usage with the 'top'
Do not miss: Find ten Linux disk directory size