Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 3354  / 1 Year ago, fri, february 24, 2023, 3:53:42

If I run top -c or htop I get processes with their memory consumption, but it is not what I want to see.


Is there a command line that allows to see the RAM consumption of a given application ?

For example, I want to see the RAM consumption of Apache web server (not by checking all the processes it runs, instead)


More From » ram

 Answers
5

There's a very good detailed explanation here: https://blogs.kde.org/2005/09/15/measuring-memory-usage



But essentially: You have to really dig in and understand how the application is set up.



So for example, looking at mysql:



  PID  PPID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                    
6004 16116 composit 20 0 37900 27m 2908 S 0 0.2 0:40.33 mysqld
16115 16085 composit 20 0 37900 27m 2908 S 0 0.2 0:00.37 mysqld
16116 16115 composit 20 0 37900 27m 2908 S 0 0.2 2:07.34 mysqld
16117 16116 composit 20 0 37900 27m 2908 S 0 0.2 0:00.00 mysqld
16118 16116 composit 20 0 37900 27m 2908 S 0 0.2 3:19.79 mysqld
16119 16116 composit 20 0 37900 27m 2908 S 0 0.2 0:00.01 mysqld
16120 16116 composit 20 0 37900 27m 2908 S 0 0.2 5:31.09 mysqld
16121 16116 composit 20 0 37900 27m 2908 S 0 0.2 14:19.53 mysqld
16122 16116 composit 20 0 37900 27m 2908 S 0 0.2 36:13.67 mysqld
16123 16116 composit 20 0 37900 27m 2908 S 0 0.2 30:30.64 mysqld
16124 16116 composit 20 0 37900 27m 2908 S 0 0.2 0:00.15 mysqld
16493 16116 composit 20 0 37900 27m 2908 S 0 0.2 0:00.00 mysqld


The total memory used is about 25 MB (Take the 27 MB RES and subtract the shared (SHR))



I validated this by checking the total memory usage (free -m, +/ buffers/cache) before and after issuing a "killall mysqld". After killing all mysqld processes, the memory usage dropped by 25 MB according to "free -m".



If you see that each process has identical VIRT, RES, and SHR columns, they are likely just threads of the same process. (Older Linux libraries handled threading by spawning multiple real processes that essentially occupied the same memory)



If they are different, you might be able to estimate it by doing a SUM of (RES - SHR). But that only works if the processes are in fact separate processes and not just threads of the same process. Looking at the PPID (Parent Process ID) also helps. If they all have the same parent, they are probably just threads (Though not necessarily).



Unfortunately there's no real good easy way to answer this in Linux. The only easy way is to check "free" immediately before terminating the process and check it again immediately after. look at the "-/+ buffers/cache:" line and see how much memory usage decreased and that will tell you how much it was using.


[#25103] Saturday, February 25, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sigtestim

Total Points: 298
Total Questions: 108
Total Answers: 106

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;