In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to query the memory occupied by the process under Linux, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Summary of the memory consumed by the query process under linux. Suppose there is a "php-cgi" process with a process id of "25282". Now you want to query the amount of memory consumed by the process. There are many tools to view under the linux command line, and now summarize several common ways
Through the status of the process
[root@web3_u] # cat / proc/25282/statusName: php-cgiState: s (sleeping) Tgid: 25282Pid: 25282PPid: 27187TracerPid: 0Uid: 99 99 99 99Gid: 99 99 99Utrace: 0FDSize: 256Groups: 99VmPeak: 496388 kBVmSize: 438284 kBVmLck: 0 kBVmHWM: 125468 kBVmRSS: 113612 kBVmData: 92588 kBVmStk: 100 kBVmExe: 6736 kBVmLib: 18760 kBVmPTE: 528 kBVmSwap: 0 kBThreads: 1SigQ: 0/46155SigPnd: 0000000000000000ShdPnd: 0000000000000000SigBlk: 0000000000000000SigIgn: 0000000000001000SigCgt: 0000000184000004CapInh: 0000000000000000CapPrm: 0000000000000000CapEff: 0000000000000000CapBnd: 0000000000000000CapBnd: ffffffffffffffffCpus_allowed: 0-3Mems0 Allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001Mems_allowed_list: 0voluntary_ctxt_switches: 68245nonvoluntary_ctxt_switches: 15751
VmRSS: 113612 kB indicates the physical memory occupied
Through pmap
[root@web3_u] # pmap-x 2528225282: / usr/local/php/bin/php-cgi-- fpm--fpm-config / usr/local/php/etc/php-fpm.confAddress Kbytes RSS Dirty Mode Mapping0000000000400000 6736 2692 20 r Murray-php-cgi0000000000c93000 264 196 120 rw--- php-cgi0000000000cd5000 60 48 48 rw--- [anon]. . .00007fd6226bc000 4 4 rw--- ld-2.12.so00007fd6226bd000 4 4 rw--- [anon] 00007fff84b02000 96 96 rw--- [stack] 00007fff84bff000 440 Ruki Xmuri-[anon] ffffffffff600000 400 r Muhashi-[anon]-total kB 438284 113612 107960
Key information point
1. Process ID
2. Start the command "/ usr/local/php/bin/php-cgi-- fpm--fpm-config / usr/local/php/etc/php-fpm.conf"
3. RSS: physical memory occupied 113612KB
Through smaps
[root@web3_u ~] # cat / proc/25282/smaps | grep'^ Rss:'\ | awk'{sum + = $2} END {print sum} '113612
The sum shows that the actual physical memory consumption is 113612.
Through the ps command
[root@web3_u] # ps-e-o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid'\ | awk' $1 ~ / 25282 Oct09 nobody 25282 php-cgi / usr/local/php/bin/php-cgi 0.0 113612 438284 Oct09 nobody 99
Awk filters the 25282 process number to find that the memory size of column 5 "rsz" is "113612".
Output the physical memory consumed by the php-cgi process and sort it from highest to lowest
[root@web3_u ~] # ps-e-o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid'\ | grep php-cgi | sort-k5nr
Output result
23946 php-cgi / usr/local/php/bin/php-cgi 0.0 129540 440000 Oct06 nobody 9924418 php-cgi / usr/local/php/bin/php-cgi 0.0 129336 437684 Oct06 nobody 9918973 php-cgi / usr/local/php/bin/php-cgi 0.0 129268 440176 Oct06 nobody 9917219 php-cgi / usr/local/php/bin/php-cgi 0.0 126588 439840 Oct06 nobody 996996 php-cgi / usr/local/php/bin/php-cgi 0.0 124876 438104 Oct09 nobody 9923850 php-cgi / Usr/local/php/bin/php-cgi 0.0 122984 440036 Oct09 nobody 9928310 php-cgi / usr/local/php/bin/php-cgi 0.0 122920 436456 Oct09 nobody 99
Where rsz is the actual memory, and in the above example, sort by memory, from large to small
Columns output by the TOP command
PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND25282 nobody 20 0428m 110m 93m S 0.01.90 php-cgi
Output column information
PID 25282
User nobody
Virtual memory 428m
Physical memory 110m 110cm 1024 = 112640 "basically consistent with the previously calculated value"
Shared memory 93m
Percentage of physical memory and total memory used by processes 1.9%
PID: process IDUSER: process owner PR: priority of the process, the smaller the priority is to be executed NInice: value VIRT: virtual memory occupied by the process RES: physical memory occupied by the process SHR: shared memory used by the process S: the status of the process. S indicates hibernation, R indicates running, Z indicates zombie, N indicates that the priority value of the process is negative% CPU: the process occupies CPU utilization% MEM: the percentage of physical memory and total memory used by the process TIME+: the total CPU time spent by the process after startup, that is, the cumulative value of CPU usage time. COMMAND: name of the process startup command
Press P
PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND16036 root 20 08902m 8.6g 480R 100.0 36.60 redis-server12934 root 33.15 redis-server12934 root 2008902m 8.6g 1072 S 5.5 36.6285 redis-server969 root 200000 D 4.2 0.0277lv 14.85 flush-252:161304 root 23 3 1689m 50m 3264 S 4.2 0.144503 xs-searchd1294 root 20 14928 928584 S 3.50.0 635R 05.31 Xs-indexd1287 nobody 20 0 12884 772 576 S 2.8 0.0 833:11.42 dnsmasq1302 root 23 3 1113m 39m 3244 S 0.7 0.2 1437:57 xs-searchd4444 www 20 0 280m 43m 884 S 0.7 0.2 27:43.92 nginx1 root 20 0 19232 1160 868 S 0.0 0.0 0:06.75 init
Press P. Means to sort by cpu, and also by cpu by default
Press M
PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND12934 root 20 08902m 8.6 g 1072 S 6.0 36.6 285 redis-server16036 root 20 08902 m 8.6 g 480 R 100.0 36.6 1 redis-server1236 www 11.42 redis-server1236 www 20 0 1053 m 209 m 6556 S 0.0 0.9 40.70 php-cgi1231 www 20 01034 m 146 m 6536 S 0.0 0.6 418 php-cgi1184 www 20 01043 m 119m 6584 S 0.0 0.5 4V 21.85 php-cgi
Press M. Indicates sorting by occupied memory. The first column of redis servers takes up 8.6 gigabytes of memory. This memory and redis info
[root@img1_u ~] # redis-cli info memory# Memoryused_memory_human:8.32G
It's basically the same.
[root@img1_u] # top-u wwwtop-22:09:01 up 67 days, 14:16, 1 user, load average: 0.61,0.90, 0.98Tasks: 283 total, 2 running, 281 sleeping, 0 stopped, 0 zombieCpu (s): 3.9%us, 1.0%sy, 0.5%ni, 89.7%id, 4.6%wa, 0.0%hi, 0.3%si, 0.0%stMem: 24542176k total, 21130060k used, 3412116k free, 1750652k buffersSwap: 524280k total, 0k used, 524280k free 4039732k cachedPID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND681 www 20 0855m 25m 5796 S 0.0 0.01 MEM TIME+ COMMAND681 www 47.00 php-cgi1181 www 20 0887m 57m 6484 S 0.0 0.2 41.66 php-cgi1183 www 200864m 34m 6320 S 0.00.1lv 52.39 php-cgi1184 www 200 1043m 119m 6584 S 0.00.5421.85 php-cgi1185 www 200869m 39m 6376 S 0.03Rule 57.84 php-cgi1186 Www 20 0 886m 56m 6244 S 0.0 0.2 3:44.75 php-cgi1187 www 20 0 926m 66m 6480 S 0.0 0.3 4:16.12 php-cgi1188 www 20 0 890m 60m 6288 S 0.0 0.3 4:13.35 php-cgi1189 www 20 0 892m 62m 6408 S 0.0 0.3 4:06.60 php-cgi
-u specifies the user. The memory occupied by php-cgi is about 60m.
The method of sorting by how much memory a process consumes
Through the ps command
The first method
Ps-e-o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid' | sort-k5nr
The second method
Ps-e-o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid'-- sort-rsz
Output result
[root@web3_u] # ps-e-o 'pid,comm,args,pcpu,rsz,vsz,stime User' | sort-k5nr23946 php-cgi / usr/local/php/bin/php-cgi 129540 440000 Oct06 nobody24418 php-cgi / usr/local/php/bin/php-cgi 0.0 129336 437684 Oct06 nobody18973 php-cgi / usr/local/php/bin/php-cgi 0.0 129268 440176 Oct06 nobody17219 php-cgi / usr/local/php/bin/php-cgi 0.0 126588 439840 Oct06 nobody6996 php-cgi / usr/local/php/bin/php-cgi 0.0 125056 438104 Oct09 nobody23850 php-cgi / Usr/local/php/bin/php-cgi 0.0 122984 440036 Oct09 nobody
Parameter resolution:
-e shows all processes
-o Custom display information
Pid process ID
Comm process name
Args start command
Percentage of CPU occupied by pcpu
Rsz occupies physical memory size
Virtual memory size consumed by vsz
Stime process startup time
User starts the user
Take the first behavior as an example
Process ID 23946 process name php-cgi startup command / usr/local/php/bin/php-cgi CPU 0 physical memory 129540 virtual memory 440000 startup time Oct06 startup user nobody
Through the top command
The top command is sorted by CPU by default and displayed by the letter "M", which can be sorted by memory footprint.
PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND23946 nobody 20 0429m 126m 107m S 0.0 2.2 1purl 15.01 php-cgi24418 nobody 20 0427m 126m 109m S 0.0 2.2 1vir 19.56 php-cgi18973 nobody 20 0429m 126m 107m S 0.0 2.2 1rig 20.18 php-cgi17219 nobody 20 0429m 123m 104m S 0.0 2.1 1purl 23.60 php-cgi6996 nobody 20 0427m 122m 105m S 0.0 1rime 05.27 php-cgi23850 nobody 20 0 429m 120m 101m S 0.0 2.1 1:02.43 php-cgi
Introduction of output parameters
PID: the ID of the process
USER: process owner
VIRT: virtual memory consumed by the process
RES: physical memory consumed by the process
SHR: shared memory used by the process
S: status of the process. S indicates hibernation, R indicates running, Z indicates dead state, and N indicates that the priority value of the process is negative
% CPU: CPU usage occupied by the process
% MEM: percentage of physical memory and total memory used by the process
TIME+: the total CPU time taken after the process was started, that is, the cumulative value of the CPU usage time occupied.
By comparing the process ID "23946", the output of the top command and the ps command are basically the same.
These are all the contents of the article "how to query the memory occupied by processes under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.