How to check memory usage per process in Linux

Written By - admin

Linux check memory usage per process. how to check which process is using more memory in Linux. Linux how much memory is a process using. Linux track process memory usage over time. linux check memory usage per process in mb. Linux check memory. linux show memory usage. linux see memory usage. linux memory usage info. linux process memory usage. how to check memory usage in linux.

How to check memory usage per process in Linux
There are several metrics available to check memory usage per process in Linux. I will begin with the two that are easiest to obtain

  • the virtual set size (vss)
  • the resident memory size (rss)

both of which are available in most implementations of the ps and top commands.


  • Vss: called VSZ in the ps command and VIRT in top, is the total amount of memory mapped by a process. It is the sum of all the regions shown in /proc/<PID>/map. This number is of limited interest, since only part of the virtual memory is committed to physical memory at any one time.
  • Rss: called RSS in ps and RES in top, is the sum of memory that is mapped to physical pages of memory. This gets closer to the actual memory budget of the process, but there is a problem, if you add up the Rss of all the processes, you will get an overestimate the memory in use because some pages will be shared.


Using top and ps to check memory usage per process (VSS and RSS)

The ps command shows Vss (VSZ) and Rss (RSS) with the options, -Aly, and a custom format which includes vsz and rss, as shown here

# ps -eo pid,tid,class,rtprio,stat,vsz,rss,comm
 1283  1283 TS       - S<sl  59636  1116 auditd
 1337  1337 TS       - Ssl  476848  9996 NetworkManager
 1366  1366 TS       - Ssl  553488 13196 polkitd
 1456  1456 TS       - S    267684 31768 sssd_nss
 1617  1617 TS       - Ss+  116376   872 agetty
 2955  2955 TS       - Ss    93728  2236 master
 4843  4843 TS       - Ss   156356  5156 sshd

Likewise free and top also shows a summary of the free memory and memory usage per process:

# free -m
              total        used        free      shared  buff/cache   available
Mem:         128814        7603       52253         153       68957      120183
Swap:          4091           0        4091

These simple commands give you a feel of the memory usage and give the first indication that you have a memory leak when you see that the Rss of a process keeps on increasing. However, they are not very accurate in the absolute measurements of memory usage.


Using smem to check memory usage per process

In 2009, Matt Mackall began looking at the problem of accounting for shared pages in process memory measurement and added two new metrics called the unique set size or Uss, and the proportional set size or Pss

  • Uss: This is the amount of memory that is committed to physical memory and is unique to a process; it is not shared with any other. It is the amount of memory that would be freed if the process were to terminate.
  • Pss: This splits the accounting of shared pages that are committed to physical memory between all the processes that have them mapped. For example, if an area of library code is 12 pages long and is shared by six processes, each will accumulate two pages in Pss. Thus, if you add the Pss numbers for all processes, you will get the actual amount of memory being used by those processes. In other words, Pss is the number we have been looking for.


The information is available in /proc/<PID>/smaps, which contains additional information for each of the mappings shown in /proc/<PID>/maps. Here is one section from such a file which provides information about the mapping for the libc code segment:

# cat /proc/31768/smaps | grep -i pss
Pss:                1132 kB
Pss:                   4 kB
Pss:                  44 kB
Pss:                  48 kB
Pss:               54632 kB
Pss:                   1 kB

<< Output trimmed >>

Pss:                   0 kB
Pss:                   0 kB
Pss:                   4 kB
Pss:                   4 kB
Pss:                   4 kB
Pss:                   0 kB
# cat /proc/31768/smaps | grep -i pss |  awk '{Total+=$2} END {print Total/1024" MB"}'
56.4102 MB

# cat /proc/31768/smaps | grep -i rss |  awk '{Total+=$2} END {print Total/1024" MB"}'
58.7109 MB

Note that the Rss is 58.7 M but because it is shared between many other processes, the Pss is only 56.4 MB.

There is a tool named smem that collates the information from the smaps files and presents it in various ways, including as pie or bar charts. The project page for smem is

There are various filters which you can apply with smem as shown below with the latest available release (1.4) at the time of writing this article

# ./smem --help
Usage: smem [options]

  -h, --help            show this help message and exit
  -H, --no-header       disable header line
  -c COLUMNS, --columns=COLUMNS
                        columns to show
  -t, --totals          show totals
  -R REALMEM, --realmem=REALMEM
                        amount of physical RAM
  -K KERNEL, --kernel=KERNEL
                        path to kernel image
  -m, --mappings        show mappings
  -u, --users           show users
  -w, --system          show whole system
                        process filter regex
                        map filter regex
                        user filter regex
  -n, --numeric         numeric output
  -s SORT, --sort=SORT  field to sort on
  -r, --reverse         reverse sort
  -p, --percent         show percentage
  -k, --abbreviate      show unit suffixes
  --pie=PIE             show pie graph
  --bar=BAR             show bar graph
  -S SOURCE, --source=SOURCE
                        /proc data source

To check memory usage per process in total we can execute below command

# ./smem -t -k
  PID User     Command                         Swap      USS      PSS      RSS
 5496 ssrun    ssRelay -pidfile /opt/mgtse        0   112.0K   152.0K   460.0K
 5522 ssrun    ssProbeframework -pidfile /        0   116.0K   156.0K   464.0K
 2072 root     rhnsd                              0   172.0K   194.0K   616.0K
 2013 root     /usr/bin/rhsmcertd                 0   172.0K   195.0K   684.0K
 1617 root     /sbin/agetty --noclear tty1        0   184.0K   196.0K   876.0K
 1493 root     /usr/sbin/atd -f                   0   260.0K   271.0K     1.1M
22058 root     /usr/sbin/rpc.idmapd               0   380.0K   384.0K   676.0K
 7802 root     /usr/sbin/xinetd -stayalive        0   396.0K   408.0K     1.1M

<< Output trimmed >> 
10901 rpc      /sbin/rpcbind -w                   0   608.0K   655.0K     1.4M
11885 oamsys   -bash                              0   524.0K   739.0K     2.2M
 4847 oamsys   -bash                              0   528.0K   743.0K     2.2M
 2008 root     /usr/sbin/oddjobd -n -p /va        0   632.0K   764.0K     1.9M
22202 sufuser  /usr/sbin/httpd -DFOREGROUN        0   372.0K   768.0K     5.4M
22203 sufuser  /usr/sbin/httpd -DFOREGROUN        0   372.0K   768.0K     5.4M
27326 sufuser  /usr/sbin/httpd -DFOREGROUN        0   372.0K   768.0K     5.4M
22199 sufuser  /usr/sbin/httpd -DFOREGROUN        0   372.0K   769.0K     5.4M
27327 sufuser  /usr/sbin/httpd -DFOREGROUN        0   372.0K   769.0K     5.4M
22201 sufuser  /usr/sbin/httpd -DFOREGROUN        0   380.0K   775.0K     5.4M
22200 sufuser  /usr/sbin/httpd -DFOREGROUN        0   380.0K   776.0K     5.4M
12096 root     -bash                              0   580.0K   809.0K     2.3M
 7989 ntp      /usr/sbin/ntpd -u ntp:ntp -        0   780.0K   814.0K     1.7M
11564 oamsys   /usr/libexec/openssh/sftp-s        0   744.0K   834.0K     2.4M
 5523 ssrun    ssProbeframework -pidfile /        0   185.3M   191.3M   198.4M
   93 11                                          0     1.9G     2.0G     2.1G

This will give you memory usage detail of every process active on your system.

To get the memory usage of a single process we can grep the process from the list

# ./smem -k | sed -e '1p' -e '/amsHelper/!d' | grep -v sed
  PID User     Command                         Swap      USS      PSS      RSS
31768 root     /sbin/amsHelper -f                 0    56.0M    56.4M    58.7M

Here as you see we get similar results as above with /proc/31768/smaps and with smem tool. So the actual memory usage of amsHelper is 56.4 MB


Lastly I hope the steps from the article to check memory usage per process on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

7 thoughts on “How to check memory usage per process in Linux”

  1. Thank you – excellent writeup!
    But I would add this, from the smem man page: The USS and PSS only include physical memory usage. They do not include memory that has been swapped out to disk”
    I’d also note that it would be faster and easier to choose the process via the -P option:
    smem -k -P amsHelper

  2. Cool! Thanks for the full ps flags to list the many kinds of memory options, as well as the tip about looking at the /proc/PID/smaps file for more information. I was trying to figure out how much memory one of my processes was consuming, but, alas, my Linux distro (running on an embedded system) has no way to install either smem or the other popular pmap tool. I’ve been just using good, old top for that, but your article gave me a vast array of many more suggestions! Thanks so much for that 🙂

  3. Awesome article. The smaps is just a nice python file. I was able to edit and enhance it to my needs. Nice article and nice set of tools.


Leave a Comment