Linux Top查看指定进程的CPU状态

查看top帮助信息

不管linux还是unix,大多数命令都是支持man命令来查看帮助信息的。
语法是下面这样,进入到交互界面后,用法类似vi,然后按「q」可以退出,输入「?」再输入关键字,可以查询相关关键字:

man top

帮助信息回显:


TOP(1)                                                                                                                       User Commands                                                                                                                       TOP(1)

NAME
       top - display Linux processes

SYNOPSIS
       top -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]
·····

·····
       -p  :Monitor-PIDs mode as:  -pN1 -pN2 ...  or  -pN1,N2,N3 ...
            Monitor only processes with specified process IDs.  This option can be given up to 20 times, or you can provide a comma delimited list with up to 20 pids.  Co-mingling both approaches is permitted.

            A pid value of zero will be treated as the process id of the top program itself once it is running.

            This is a command-line option only and should you wish to return to normal operation, it is not necessary to quit and restart top  --  just issue any of these interactive commands: '=', 'u' or 'U'.

            The 'p', 'u' and 'U' command-line options are mutually exclusive.

执行命令

找到帮忙信息之后,在「top」后面接上参数 「-p」就可以,还可以接多个这样的参数。下面是实例。

top -p222 -p235

结果预览

top - 10:59:27 up 8 days, 23:04, 33 users,  load average: 19.29, 18.88, 15.68
Tasks:   2 total,   0 running,   2 sleeping,   0 stopped,   0 zombie
%Cpu(s): 28.0 us,  2.2 sy,  0.0 ni, 66.1 id,  3.5 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem:  13192180+total, 12092056+used, 11001252 free, 58405476 buffers
KiB Swap: 13410816+total,    75264 used, 13403289+free. 34504364 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                                                                                  
  222 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/42:0H                                                                                                                                                                                            
  235 root      20   0       0      0      0 S   0.0  0.0   0:01.74 ksoftirqd/45

小结

遇到不会的Linux命令,不要慌、莫着急,用「man」查看帮助信息,帮忙信息太多,可以用用「/」或者「?」加上关键字可以搜索,可以说非常方便。还有一点就是多实践操作。

你可能感兴趣的:(Linux)