ps查看进程
root@zihome:/proc/2111# ps | grep ZGateway
2111 root 76112 S {MainThread} /zihome/plugins/zgateway/ZGateway /dev/ttyS2 /dev/ttyS1
2114 root 1520 S {ZGatewayTimerCh} /bin/sh /zihome/plugins/zgateway/ZGatewayTimerCheck.sh /zihome/plugins/zgateway/run.sh
12072 root 1520 S grep ZGateway
然后cat status
root@zihome:/# cat proc/2111/status
Name: MainThread
State: S (sleeping)
Tgid: 2111
Pid: 2111
PPid: 1
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 256
Groups:
VmPeak: 76204 kB
VmSize: 76112 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 8948 kB
VmRSS: 8940 kB
VmData: 64236 kB
VmStk: 136 kB
VmExe: 3024 kB
VmLib: 8464 kB
VmPTE: 92 kB
VmSwap: 0 kB
Threads: 37
SigQ: 0/981
SigPnd: 00000000000000000000000000000000
ShdPnd: 00000000000000000000000000000000
SigBlk: 00000000000000000000000000001000
SigIgn: 00000000000000000000000000000004
SigCgt: 0000000000000000000000018002d003
CapInh: 0000000000000000
CapPrm: 0000001fffffffff
CapEff: 0000001fffffffff
CapBnd: 0000001fffffffff
Cpus_allowed: f
Cpus_allowed_list: 0-3
voluntary_ctxt_switches: 7531
nonvoluntary_ctxt_switches: 174
-
VmSize(KB) 任务虚拟地址空间的大小 (total_vm-reserved_vm),其中total_vm为进程的地址空间的大小,reserved_vm:进程在预留或特殊的内存间的物理页
-
VmLck(KB) 任务已经锁住的物理内存的大小。锁住的物理内存不能交换到硬盘 (locked_vm)
-
VmRSS(KB) 应用程序正在使用的物理内存的大小,就是用ps命令的参数rss的值 (rss)
-
VmData(KB) 程序数据段的大小(所占虚拟内存的大小),存放初始化了的数据; (total_vm-shared_vm-stack_vm)
-
VmStk(KB) 任务在用户态的栈的大小 (stack_vm)
-
VmExe(KB) 程序所拥有的可执行虚拟内存的大小,代码段,不包括任务使用的库 (end_code-start_code)
-
VmLib(KB) 被映像到任务的虚拟内存空间的库的大小 (exec_lib)
-
VmPTE 该进程的所有页表的大小,单位:kb
-
Threads 共享使用该信号描述符的任务的个数,在POSIX多线程序应用程序中,线程组中的所有线程使用同一个信号描述符
-
1、VmRSS是真实正在占用的内存,而VmData是虚拟内存,大小差异大并没有什么问题。
-
2、VmData是指数据段的内存大小,存放初始化了的数据; (total_vm-shared_vm-stack_vm)
-
3、不调动态库的时候是不计算的(dlopen方式)
-
4、静态库会编译为程序本身的一部分,不在VmLib的统计之内。
-
5、参考上面的说明
-
6、除非有非常明显的内存泄露,如内存一直大幅度增长并长时间不释放,否则单纯以来这些值是很判断真正的内在泄露。
top也可以看到VmSize(KB)任务虚拟地址空间的大小
Mem: 60008K used, 65840K free, 0K shrd, 3056K buff, 16484K cached
CPU: 2% usr 2% sys 0% nic 95% idle 0% io 0% irq 0% sirq
Load average: 0.33 0.43 0.43 3/124 13525
PID PPID USER STAT VSZ %VSZ %CPU COMMAND
2111 1 root S 76112 60% 2% {MainThread} /zihome/plugins/zgateway
13525 8985 root R 1528 1% 2% top
2113 1 root S 14172 11% 0% {tclapp_release} /zihome/plugins/zgat
2112 1 root S 8268 7% 0% /zihome/plugins/zgateway/ygCustomLock
2020 1 root S 7444 6% 0% /zihome/plugins/zgateway/AmberGwZ3 -n
1532 1 root S 3636 3% 0% mosquitto -c /etc/mosquittoConf/mosqu
1575 1 root S 3620 3% 0% zihome_sub -c -h 152.136.148.124 -p 7
1966 1 root S 2624 2% 0% {zihomescript.sh} /bin/sh /zgateway/z
1079 1 root S 1996 2% 0% /sbin/logd -S 934
2188 1278 root S 1720 1% 0% /usr/sbin/pppd nodetach ipparam wan i
1176 1 root S 1708 1% 0% /usr/sbin/mtkwifi -i E4:F3:E8:D3:8B:5
1591 1 root S 1636 1% 0% /usr/bin/zdetect
1278 1 root S 1608 1% 0% /sbin/netifd
1088 1 root S 1588 1% 0% /sbin/rpcd
1597 1591 root S 1580 1% 0% /usr/bin/zdetect
1413 1 root S 1556 1% 0% /usr/sbin/uhttpd -f -h /www -r zihome
8985 8910 root S 1536 1% 0% -ash
7095 7046 root S 1532 1% 0% -ash
2114 1 root S 1520 1% 0% {ZGatewayTimerCh} /bin/sh /zihome/plu
^C390 1 root S 1520 1% 0% /usr/sbin/telnetd -F -l /bin/login.sh