查看进程的内存和CPU占用

时间:2021-10-13 12:14:54

方法1:

ps -p <pid> -o %cpu,%mem,cmd
例子:

$ ps -p 12902 -o %cpu,%mem,cmd
%CPU %MEM CMD
36.1 10.0 /usr/lib/firefox/firefox

or:

$ ps -C firefox -o %cpu,%mem,cmd
%CPU %MEM CMD
35.7 10.1 /usr/lib/firefox/firefox

or:

$ pidstat -h -r -u -v -p 12902,6525
Linux 4.4.8-040408-generic (xiaotao) 	10/28/2016 	_i686_	(4 CPU)

#      Time   UID       PID    %usr %system  %guest    %CPU   CPU  minflt/s  majflt/s     VSZ     RSS   %MEM threads   fd-nr  Command
 1477662803  1000     12902    1.54    0.16    0.00    1.70     1    222.19      0.00 1383800  414136  10.13 4294967345 4294967373  firefox
 1477662803  1000      6525    0.01    0.00    0.00    0.01     3      0.30      0.00  300736   67540   1.65 12884901895      -1  chrome

or

$ top -b -n 1 -p  12902 | tail -2
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
12902 charles   20   0 1383380 413580 156696 S   0.0 10.1  22:22.62 firefox