slm*_*slm 29
我处理信号量和共享内存的唯一经验是通过使用命令ipcs。有关更多详细信息,请查看ipcs 手册页。
此命令显示哪些进程具有信号量:
$ ipcs -s
------ Semaphore Arrays --------
key semid owner perms nsems
0x4d114854 65536 saml 600 8
Run Code Online (Sandbox Code Playgroud)
已知 semid 后,我们可以查询有关具有信号量的 PID 的附加信息(注意有 8 个 - nsems 列):
$ ipcs -s -i 65536
Semaphore Array semid=65536
uid=500 gid=501 cuid=500 cgid=501
mode=0600, access_perms=0600
nsems = 8
otime = Sun May 12 14:44:53 2013
ctime = Wed May 8 22:12:15 2013
semnum value ncount zcount pid
0 1 0 0 0
1 1 0 0 0
2 1 0 0 2265
3 1 0 0 2265
4 1 0 0 0
5 1 0 0 0
6 1 0 0 4390
7 1 0 0 4390
Run Code Online (Sandbox Code Playgroud)
pid 列是这些进程。您可以使用ps或查看/proc文件系统/proc/<pid>.
例如:
$ more /proc/2265/cmdline
mono
Run Code Online (Sandbox Code Playgroud)
根据@lgeorget 留下的评论,我深入研究了 PID 2265 的/proc/2265/map内容,并找到了以下/dev/shm参考资料:
$ grep shm /proc/2265/maps
7fa38e7f6000-7fa38ebdf000 rw-s 00000000 00:11 18517 /dev/shm/mono-shared-500-shared_fileshare-grinchy-Linux-x86_64-40-12-0
7fa38f0ca000-7fa38f0cb000 rw-s 00000000 00:11 18137 /dev/shm/mono.2265
7fa3967be000-7fa3967d3000 rw-s 00000000 00:11 18516 /dev/shm/mono-shared-500-shared_data-grinchy-Linux-x86_64-328-12-0
Run Code Online (Sandbox Code Playgroud)