0

Let's say I see a file called /dev/shm/some.segment

How can I find out (with command lines):

  1. The processes that are linked to it?

  2. The NUMA node it locates?

For #2, I can write a small C program with move_pages() to find out. Just wonder whether there is something handy.

I am on CentOS 7 if it matters.

Thanks!

================

Update (Tried harrymc's suggestion):

[myuser@mylinux ~]$ ipcs -pm

------ Shared Memory Creator/Last-op PIDs --------
shmid      owner      cpid       lpid      
131072     myuser      2999       3144      
163841     myuser      2999       3144      
262146     myuser      3226       3288      
753667     myuser      3288       2006      
655364     myuser      3226       2006      
360453     myuser      2819       4036      
622598     myuser      3226       2006      
589831     myuser      3226       2006      
524296     myuser      3226       2006      
786441     myuser      3226       2006      
819210     myuser      3226       2006      
917515     myuser      4042       4050      
950284     myuser      4099       4099      
1048589    myuser      4106       4839      

[myuser@mylinux ~]$ sudo grep 131072 /proc/*/maps
/proc/2006/maps:7f252828b000-7f252830b000 rw-s 00000000 00:04 131072                     /SYSV00000000 (deleted)
/proc/2999/maps:7f2854017000-7f2854097000 rw-s 00000000 00:04 131072                     /SYSV00000000 (deleted)
[myuser@mylinux ~]$ sudo grep 163841 /proc/*/maps
/proc/2006/maps:7f2527e8b000-7f252828b000 rw-s 00000000 00:04 163841                     /SYSV00000000 (deleted)
/proc/2999/maps:7f2844a12000-7f2844e12000 rw-s 00000000 00:04 163841                     /SYSV00000000 (deleted)
[myuser@mylinux ~]$ sudo grep 262146 /proc/*/maps
/proc/2006/maps:7f2527e2b000-7f2527e8b000 rw-s 00000000 00:04 262146                     /SYSV00000000 (deleted)
/proc/3226/maps:7f28ce834000-7f28ce894000 rw-s 00000000 00:04 262146                     /SYSV00000000 (deleted)
[myuser@mylinux ~]$ sudo grep 1048589 /proc/*/maps
/proc/2006/maps:7f2524c99000-7f2525499000 rw-s 00000000 00:04 1048589                    /SYSV00000000 (deleted)
/proc/4106/maps:7fe5af800000-7fe5b0000000 rw-s 00000000 00:04 1048589                    /SYSV00000000 (deleted)
[myuser@mylinux ~]$ ll /dev/shm/
total 1000
-rwx------ 1 myuser myuser 67108904 Sep 23 09:42 pulse-shm-1190977916
-rwx------ 1 myuser myuser 67108904 Sep 23 09:48 pulse-shm-1218108161
-rwx------ 1 myuser myuser 67108904 Sep 23 10:03 pulse-shm-1238825830
-rwx------ 1 myuser myuser 67108904 Sep 23 10:03 pulse-shm-13579424
-rwx------ 1 myuser myuser 67108904 Sep 23 09:42 pulse-shm-2544170821
-rwx------ 1 gdm   gdm   67108904 Sep 23 09:42 pulse-shm-2626080508
-rwx------ 1 gdm   gdm   67108904 Sep 23 09:42 pulse-shm-3289673610
-rwx------ 1 myuser myuser 67108904 Sep 23 09:42 pulse-shm-4099527713
-rwx------ 1 myuser myuser 67108904 Sep 23 09:42 pulse-shm-52369360
[myuser@mylinux ~]$ lsof /dev/shm/pulse-shm-1190977916
COMMAND    PID  USER  FD   TYPE DEVICE SIZE/OFF  NODE NAME
pulseaudi 2663 myuser mem    REG   0,19 67108904 34513 /dev/shm/pulse-shm-1190977916
[myuser@mylinux ~]$ ps aux | grep 2663
myuser     2663  0.2  0.0 640560  8044 ?        S<l  09:42   0:03 /usr/bin/pulseaudio --start --log-target=syslog
myuser     8144  0.0  0.0 112712   972 pts/0    S+   10:05   0:00 grep --color=auto 2663
[myuser@mylinux ~]$ 

1 Answer 1

0

The lsof command should supply most of that information.

You may grep its output for the shmid, which you may find using ipcs -m.

9
  • Thanks for your answer. But I noticed that lsof's output doesn't contain shmid. And the strange thing is that the sizes in ipcs -m don't match any size in ls -l /dev/shm. ipcs -m doesn't tell me which processes (PIDs) are linked to the specific SHM. Tho, it does tell me how many processes are linked to the specific SHM. Both commands don't show which NUMA node the SHM resides on tho.
    – HCSF
    Commented Sep 22, 2018 at 11:59
  • Strange. Could you add those outputs to your post?
    – harrymc
    Commented Sep 22, 2018 at 12:08
  • The discrepancy might be due to ipcs reporting SysV shm, while /dev/shm is for POSIX shm? I'm not sure on that one I'm sure, however, that some programs just create files there directly without using any special API, and so only fuser/lsof would work with those. Commented Sep 22, 2018 at 12:31
  • Try grep <shmid> /proc/*/maps. See also this script.
    – harrymc
    Commented Sep 22, 2018 at 13:31
  • @grawity it is possible as I just tried harrymc's suggestion with grep <shmid> /proc/*/maps with couple shmids, and all ended with /SYSV[some numbers]
    – HCSF
    Commented Sep 22, 2018 at 15:43

You must log in to answer this question.

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