Linux 查看进程

杀掉登录用户:

w
 20:46:40 up 12 days,  4:28,  4 users,  load average: 0.30, 0.12, 0.07
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    112.97.63.53     20:28    0.00s  0.07s  0.00s w
root     pts/2    125.94.151.83    14:08    3:31m  0.04s  0.04s -bash

ps -ef | grep pts/2

#向上寻找父进程ID
kill -9 pid

动态查看进程CPU内存

#-d 1表示1秒刷新
top -d 1 -p pid

这个可以查看百分比,比如内存占用,如果要查看进程实际霸占的内存,可以通过ps命令。

查看进程霸占内存:

ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

RSS对应实际霸占的内存(KB),这里需要知道,进程占用内存一般是指堆内存(其它一般占比较少),而堆内存内中是有空闲的,不过这个都归到进程内存占用。另外,如果要查看进程更加详细的信息:

cat /proc/pid/status

Name:	node
State:	S (sleeping)
Tgid:	31897
Ngid:	0
Pid:	31897    进程号
PPid:	1        父进程
TracerPid:	0
Uid:	0	0	0	0
Gid:	0	0	0	0
FDSize:	256
Groups:	0 
VmPeak:	 1302912 kB
VmSize:	 1301888 kB
VmLck:	       0 kB
VmPin:	       0 kB
VmHWM:	  123372 kB
VmRSS:	  122772 kB实际霸占内存
VmData:	 1262976 kB
VmStk:	     136 kB
VmExe:	   19980 kB
VmLib:	    4056 kB
VmPTE:	     636 kB
VmSwap:	       0 kB
Threads:	9  线程数量
SigQ:	0/31225
SigPnd:	0000000000000000
ShdPnd:	0000000000000000
SigBlk:	0000000000000000
SigIgn:	0000000000001000
SigCgt:	0000000188004202
CapInh:	0000000000000000
CapPrm:	0000001fffffffff
CapEff:	0000001fffffffff
CapBnd:	0000001fffffffff
Seccomp:	0
Cpus_allowed:	7fff
Cpus_allowed_list:	0-14
Mems_allowed:	00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
Mems_allowed_list:	0
voluntary_ctxt_switches:	1373
nonvoluntary_ctxt_switches:	4465