How much RAM is this application using?
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.
With a bit of help from man ps
and this great answer...
ps -up $(pidof PROCESS_NAME)
For example:
[wilf@comp ~]$ ps -up $(pidof firefox)
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
wilf 1619 8.9 5.6 1464216 342396 ? Sl 17:56 1:36 /usr/lib64/firefox/firefox
[wilf@comp ~]$
Other ways:
cat /proc/$(pidof firefox)/status | grep VmSize
This can be run without -x
and tail -1
:
pmap -x $(pidof firefox) | tail -1
only shows percentage:
top -p $(pidof firefox)
Also, whilst using top
you can press i to ignore idle/zombie processes to make it easier to read: