How do I determine what process is attached to a shared memory segment?
awagner@tree:/home/awagner$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 0 root 777 102400 1
0x00000000 32769 root 774 96 1 dest
0x00000000 98306 awagner 600 393216 2 dest
0x00000000 131075 awagner 600 393216 2 dest
i.e. how do I figure out which two processes are attached to shmid 98306?
This question is related to
linux
memory
memory-management
shared
Use ipcs -a
: it gives detailed information of all resources [semaphore, shared-memory etc]
Here is the image of the output:
given your example above - to find processes attached to shmid 98306
lsof | egrep "98306|COMMAND"
I wrote a tool called who_attach_shm.pl, it parses /proc/[pid]/maps to get the information. you can download it from github
sample output:
shm attach process list, group by shm key
##################################################################
0x2d5feab4: /home/curu/mem_dumper /home/curu/playd
0x4e47fc6c: /home/curu/playd
0x77da6cfe: /home/curu/mem_dumper /home/curu/playd /home/curu/scand
##################################################################
process shm usage
##################################################################
/home/curu/mem_dumper [2]: 0x2d5feab4 0x77da6cfe
/home/curu/playd [3]: 0x2d5feab4 0x4e47fc6c 0x77da6cfe
/home/curu/scand [1]: 0x77da6cfe
Just in case someone is interest only in what kind of process created the shared moeries, call
ls -l /dev/shm
It lists the names that are associated with the shared memories - at least on Ubuntu. Usually the names are quite telling.
Source: Stackoverflow.com