In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to view the memory usage of processes and users in the Linux system, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Check memory usage by process using top
Top is one of the best commands to view memory usage. To see which process uses the most memory, an easy way is to start top and then press shift+m so that you can see the processes arranged from highest to lowest by percentage of memory usage. When you press shift+m, your top should get output similar to the following:
Toptop-09:39:34 up 5 days, 3 min, 3 users, load average: 4.77,4.43, 3.72Tasks: 251 total, 3 running, 247 sleeping, 1 stopped, 0 zombie%Cpu (s): 50.6 us, 35.9 sy, 0.0 ni, 13.4 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 stMiB Mem: 5944.4 total, 128.9 free, 2509.3 used 3306.2 buff/cacheMiB Swap: 2048.0 total, 2045.7 free, 2.2 used. 3053.5 avail Mem PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND 400 nemo 20 3309580 550188 168372 S 0.3 9.01 Web Content32469 nemo 33.27 Web Content32469 nemo 20 3492840 447372 163296 S 7.333 Vol 55.60 firefox32542 nemo 20 2845732 433388 140984 S 6.0 7.14 Vol 11.16 Web Content 342 nemo 20 2848520 352288 118972 S 10. 3 5.8 4:04.89 Web Content 2389 nemo 20 0 1774412 236700 90044 S 39.7 3.9 9:32.64 vlc29527 nemo 20 0 2735792 225980 84744 S 9.6 3.7 3:02.35 gnome-shell30497 nemo 30 10 1088476 159636 88884 S 0.0 2.6 0:11.99 update-manager30058 nemo 20 0 1089464 140952 33128 S 0.0 2.3 0:04.58 gnome-software32533 nemo 20 0 2389088 104712 79544 S 0.0 1.7 0:01.43 WebExtensions 2256 nemo 20 0 1217884 103424 31304 T 0.0 1.7 0:00.28 vlc 1713 nemo 20 0 2374396 79588 61452 S 0.0 1.3 0:00.49 Web Content29306 nemo 20 0 389668 74376 54340 S 2.3 1.2 0:57.25 Xorg32739 nemo 20 0 289528 58900 34480 S 1.0 1.0 1:04.08 RDD Process29732 nemo 20 0 789196 57724 42428 S 0.0 0.9 0:00.38 evolution-alarm 2373 root 20 0 150408 57000 9924 S 0.3 0.9 10:15.35 nessusd
Notice the% MEM sort. The size of the list depends on the size of your window, but the processes that occupy the most memory will be displayed at the top of the list.
Use ps
A column in the ps command shows the memory usage of each process. To show and see which process uses the most memory, you can pass the result of the ps command to the sort command. Here is a useful example:
$ps aux | sort-rnk 4 | head-5nemo 400 3.49.2 3309580 563336? Sl 08:59 1:36 / usr/lib/firefox/firefox-contentproc-childID 6-isForBrowser-prefsLen 9086-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni / usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 32469 8.2 7.7 3492840 469516? Sl 08:54 4:15 / usr/lib/firefox/firefox-new-windownemo 32542 8.9 7.6 2875428 462720? Sl 08:55 4:36 / usr/lib/firefox/firefox-contentproc-childID 2-isForBrowser-prefsLen 1-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni / usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 342.9.9 2854664 363528? Sl 08:59 4:44 / usr/lib/firefox/firefox-contentproc-childID 5-isForBrowser-prefsLen 8763-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni / usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 2389 39.5 3.1774412 236116 pts/1 Sl+ 09:15 12:21 vlc videos/edge_computing.mp4
In the above example (truncated in this article), the sort command uses the-r option (reverse), the-n option (numeric value), and the-k option (keyword) to have the sort command sort and output the results of the ps command in reverse order according to the numbers in the fourth column (memory usage). If we first display the title of the ps command, it will be easy to see.
$ps aux | head-1; ps aux | sort-rnk 4 | head-5USER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMANDnemo 400 3.4.9.2 3309580 563336? Sl 08:59 1:36 / usr/lib/firefox/firefox-contentproc-childID 6-isForBrowser-prefsLen 9086-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni / usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 32469 8.2 7.7 3492840 469516? Sl 08:54 4:15 / usr/lib/firefox/firefox-new-windownemo 32542 8.9 7.6 2875428 462720? Sl 08:55 4:36 / usr/lib/firefox/firefox-contentproc-childID 2-isForBrowser-prefsLen 1-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni / usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 342.9.9 2854664 363528? Sl 08:59 4:44 / usr/lib/firefox/firefox-contentproc-childID 5-isForBrowser-prefsLen 8763-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni / usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 2389 39.5 3.1774412 236116 pts/1 Sl+ 09:15 12:21 vlc videos/edge_computing.mp4
If you like this command, you can assign him an alias with the following command, and if you want to use it all the time, don't forget to add the command to your ~ / .bashrc file.
$alias mem-by-proc= "ps aux | head-1; ps aux | sort-rnk 4"
Here are some commands to view memory usage based on the user:
Use top to view memory usage by user
Checking memory usage by the user is more complicated because you need to find a way to count all the processes owned by the user as a single memory usage.
If you only want to see how individual user processes are being used, the top command can be used in the same way as above. Just add the-U option and specify the user name you want to view after it, and then press shift+m to view it by using more or less memory.
$top-U nemotop-10:16:33 up 5 days, 40 min, 3 users, load average: 1.91,1.82, 2.15Tasks: 253 total, 2 running, 250 sleeping, 1 stopped, 0 zombie%Cpu (s): 28.5 us, 36.8 sy, 0.0 ni, 34.4 id, 0.3 wa, 0.0 hi, 0.0 si, 0.0 stMiB Mem: 5944.4 total, 224.1 free, 2752.9 used 2967.4 buff/cacheMiB Swap: 2048.0 total, 2042.7 free, 5.2 used. 2812.0 avail Mem PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND 400 nemo 20 0 3315724 165440 S 1.0 10.2 1 Web Content32469 nemo 48.78 Web Content32469 nemo 20 0 3629380 607492 1688 S 2.3 10.06 firefox32542 nemo 06.89 firefox32542 nemo 20 0 2886700 404980 136648 S 5.667 MEM TIME+ COMMAND 50.01 Web Content 342 nemo 20 02922248 375784 116096 S 19.5 6.2 8:16.07 Web Content 2389 nemo 20 0 1762960 234644 87452 S 0.0 3.9 13:57.53 vlc29527 nemo 20 0 2736924 227260 86092 S 0.0 3.7 4:09.11 gnome-shell30497 nemo 30 10 1088476 156372 85620 S 0.0 2.6 0:11.99 update-manager30058 nemo 20 0 1089464 138160 30336 S 0.0 2.3 0:04.62 gnome-software32533 nemo 20 0 2389088 102532 76808 S 0.0 1.7 0 01.79 WebExtensions using ps
You can still use the ps command to arrange a user's processes according to memory usage. In this example, we will use the grep command to filter all processes that get a user.
$ps aux | head-1; ps aux | grep ^ nemo | sort-rnk 4 | moreUSER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMANDnemo 32469 7.1 11.5 3724364 701388? Sl 08:54 7:21 / usr/lib/firefox/firefox-new-windownemo 400 2.0 8.9 3308556 543232? Sl 08:59 2:01 / usr/lib/firefox/firefox-contentproc-childID 6-isForBrowser-prefsLen 9086-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni/usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 32542 7.9 7.1 2903084 436196? Sl 08:55 8:07 / usr/lib/firefox/firefox-contentproc-childID 2-isForBrowser-prefsLen 1-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni / usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 342 10.8 7.0 2941056 426484? Rl 08:59 10:45 / usr/lib/firefox/firefox-contentproc-childID 5-isForBrowser-prefsLen 8763-prefMapSize 210653-parentBuildID 20200107212822-greomni / usr/lib/firefox/omni.ja-appomni / usr/lib/firefox/browser/omni.ja-appdir / usr/lib/firefox/browser 32469 true tabnemo 2389 16.9 3.8 1762960 234644 pts/1 Sl+ 09:15 13:57 vlc videos/edge_computing.mp4nemo 29527 3.9 3.7 2736924 227448? Ssl 08:50 4:11 / usr/bin/gnome-shell uses ps with other commands
It will be more complicated if you want to compare the memory usage of one user with that of other users. In this case, it's a good idea to create and sort one according to the user's total memory usage, but it requires some more work and involves a lot of commands. In the following script, we use the ps aux | grep-v COMMAND | awk'{print $1}'| sort-u command to get a list of users. It includes system users such as syslog. We use the awk command for each task to collect the total memory usage of each user. In the final step, we show the total memory usage for each user (in order from largest to smallest).
#! / bin/bash stats= "" echo "% user" echo "=" # collect the datafor user in `ps aux | grep-v COMMAND | awk'{print $1}'| sort-u`do stats= "$stats\ n`ps aux | egrep ^ $user | awk 'BEGIN {total=0};\ {total + = $4}; END {print total,$1}' `" done # sort data numerically (largest first) echo-e $stats | grep-v ^ $| sort-rn | head
The output of this script might be as follows:
$. / show_user_mem_usage% user=69.6 nemo5.8 root0.5 www-data0.3 shs0.2 whoopsie0.2 systemd+0.2 colord0.2 clamav0 syslog0 rtkit Thank you for reading this article carefully. I hope the article "how to check the memory usage of processes and users in Linux system" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!
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.