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 ~]$ 
HCSF
  • 165
  • 1
  • 11

1 Answers1

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.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • 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 Sep 22 '18 at 11:59
  • Strange. Could you add those outputs to your post? – harrymc Sep 22 '18 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. – u1686_grawity Sep 22 '18 at 12:31
  • Try `grep /proc/*/maps`. See also [this script](https://github.com/curu/linuxplayer/blob/master/scripts/who_attach_shm.pl). – harrymc Sep 22 '18 at 13:31
  • @grawity it is possible as I just tried harrymc's suggestion with `grep /proc/*/maps` with couple shmids, and all ended with `/SYSV[some numbers]` – HCSF Sep 22 '18 at 15:43
  • @harrymc I looked at the script you linked to. It also hardcoded to search for a pattern with "/SYSV". So it seems `/proc/*/maps` are holding SYSV based shared memory only? – HCSF Sep 22 '18 at 15:45
  • Could you also post the output of the grep? Ensure that all the outputs in your post belong together to the same processes. – harrymc Sep 22 '18 at 15:47
  • And why didn't you run `ipcs -pm` ? That gives at least two processes : creator and last-attached. – harrymc Sep 22 '18 at 16:09
  • @harrymc Just posted (all commands ran in 1 session). `ipcs -pm` indeed gives me 2 PIDs -- creator and last access. But they don't tell me which processes are currently attached to the SHM (my original question #1). Thanks. – HCSF Sep 23 '18 at 02:09