I need to know the amount of memory shared between two processes, that is, the intersection of their shared memories.

Any ideas?

  • doesn't top commands help? Nov 16, 2016 at 11:50
  • 1
    Which OS? Do you just want a number like "5342 kilobytes", or do you want to know which objects are shared? Nov 16, 2016 at 11:55
  • @MarkPlotnick : I guess OP has explicitly mentioned "Amount of memory" So I don't think he is looking for "which objects are shared."
    – Thushi
    Nov 16, 2016 at 12:04
  • ipcs -m may be the answer. Nov 16, 2016 at 12:17
  • Are you interested in just shared memory segments (shmget()), or also shared memory due to process fork & copy-on-write, mmap()ped files, etc?
    – phemmer
    Nov 16, 2016 at 13:32

1 Answer 1


You can look at /proc/<pid>/maps, /proc/<pid>/smaps (or pmap -x <pid> if your OS supports) of interested process ID's and compare outputs to determine shared memory regions. That includes shared memory segments via shmget calls, as well as any shared libraries, files.

Edit: As mr.spuratic pointed out his answer here has more details on kernel side

You can look at a process RSS using ps, however it doesn't take into consideration all the shared pages. To see RSS for specific process, see below

cv@thunder:~$ ps -o rss,pid,comm -p $$,7023
22060  7023 xfwm4
 6876 18094 bash

smem tool provides more detailed information, taking into consideration of shared pages. See below output for the same above process

cv@thunder:~$ smem -t |egrep "RSS|$$|7023"
  PID User     Command                         Swap      USS      PSS      RSS 
 9852 cv       grep -E RSS|18094|7023             0      340      367     2220 
18094 cv       bash                               0     3472     4043     6876 
 7023 cv       xfwm4 --display :0.0 --sm-c        0     5176     7027    22192 

From man smem:

   smem  reports  physical  memory usage, taking shared memory pages into account.  Unshared memory is reported as the USS (Unique Set Size).  Shared
   memory is divided evenly among the processes sharing that memory.  The unshared memory (USS) plus a  process's  proportion  of  shared  memory  is
   reported  as  the  PSS  (Proportional  Set  Size).   The USS and PSS only include physical memory usage.  They do not include memory that has been
   swapped out to disk.
  • thanks @VenkatC, this is insightful, but the memory addresses these files refer in their records are virtual (process space), so I can't see how they overlap. Any way of seeing how they map to physical addresses?
    – idelvall
    Nov 16, 2016 at 17:08
  • @idelvall /proc/kpageflags, see my answer to a related question here which explains some relevant kernel details. Nov 16, 2016 at 17:21
  • @idelvall you can see shared segments with 's' flag in and read more info at kernel.org/doc/Documentation/vm/pagemap.txt on converting virtual to physical.
    – VenkatC
    Nov 16, 2016 at 18:40
  • @idelvall also, what are trying exactly trying to find out or what problem are you trying to resolve?
    – VenkatC
    Nov 16, 2016 at 18:43
  • @VenkatC i want to know the total amount of RSS of a set of processes
    – idelvall
    Nov 16, 2016 at 20:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .