Memory occupied by CentOS Query Process
1. ps aux command user pid % CPU % mem vsz rss tty stat start time COMMANDlizhibin 32986 0.0 13.8 916276 534748? Ssl/usr/local/php_5.4.45/bin/php-c/usr/local/php_5.4.45/etc/php-swoole.ini/www/service.gamechat.37.com/server.phplizhibin 32988 0.0 13.8 768812 534272? S/usr/local/php_5.4.45/bin/php-c/usr/local/php_5.4.45/etc/php-swoole.ini/www/service.gamechat.37.com/server.phplizhibin 32993 0.0 13.8 764704 534752? S/usr/local/php_5.4.45/bin/php-c/usr/local/php_5.4.45/etc/php-swoole.ini/www/service.gamechat.37.com/server.phplizhibin 32994 0.0 13.8 764704 534752? S/usr/local/php_5.4.45/bin/php-c/usr/local/php_5.4.45/etc/php-swoole.ini/www/service.gamechat.37.com/server.phplizhibin 32995 0.0 13.8 764704 534752? S/usr/local/php_5.4.45/bin/php-c/usr/local/php_5.4.45/etc/php-swoole.ini/www/service.gamechat.37.com/server.phplizhibin 32996 0.0 13.8 764704 534752? S/usr/local/php_5.4.45/bin/php-c/usr/local/php_5.4.45/etc/php-swoole.ini/www/service.gamechat.37.com/server.phpvsz:rss the process occupies multiple virtual memory (kb) RSS: indicates the amount of physical memory occupied by the process (kb). We can simplify the command: ps aux | grep swoole | grep-v grep | awk-F ''' {print $5, $6} '2017 916276 534748768812 534272764704 534752764704 534752764704 534752764704 you can see that each swoole process occupies 534752 + MB of physical memory every month. 2. run the pmap command pmap-d 3298832988: /usr/local/php_5.4.45/bin/php-c/usr/local/php_5.4.45/etc/php-swoole.ini/www/service.gamechat.37.com/server.phpAddress Kbytes Mode Offset Device mapping1_00400000 10272 r-x -- 0000000000000000 0fd: 00000 php0000000001007000 4 r ---- 0000000000a07000 0fd: 00000 php0000000001008000 60 rw --- 0000000000a08000 0fd: 00000 php0000000001017000 140 rw --- 0000000000000000 000: 00000 [anon] running 000002a69000 301936 rw --- 0000000000000000 000:00000 [anon] running 7fcec91e4000 224380 rw --- 0000000000000000 000:00000 [anon] command output the first line: Execution program and parameters. Address: memory start Address Kbytes: number of bytes in memory (KB) RSS: number of bytes in memory reserved (KB) Dirty: number of bytes in Dirty pages (including shared and private ones) (KB) Mode: Memory permission: read, write, execute, shared, private (copy at write time) Mapping: memory-occupied file, or [anon] (allocated memory), or [stack] (stack) Offset: file Offset Device: Device Name (major: minor) we use the awk command, calculate the sum of the Kbytes column and pmap-dq 32988 | awk-F ''' BEGIN {sum = 0} {sum + = $2} END {print sum} 'result output: 768812KB, the result is the virtual memory size in the ps command. Then, filter out the shared memory of so. Pmap-dq 32988 | awk-F ''' BEGIN {sum = 0} {if ($6 !~ /\. So/) sum + = $2} END {print sum} 'result output: 672284KB, which is different from the physical memory data obtained by the ps command. Adjust the command: pmap-dq 32988 | awk-F ''' BEGIN {sum = 0} {if ($6 ~ /\ [/) Sum + = $2} END {print sum} 'result output: 53664kb, which is close to the physical memory obtained by the ps command. The preceding command mainly counts the memory (stack) occupied by the Process [anon] and [stack)