简体   繁体   English

ipcs 不显示我的共享内存和信号量

[英]ipcs doesn't show my shared memory and semaphores

I open shared memory and semaphores with the appropriate flags:我使用适当的标志打开共享内存和信号量:

sem = sem_open("/some_name", O_CREAT | O_EXCL, S_IRWXU | S_IRWXG | S_IRWXO, 1);
shm = shm_open("/other_name", O_RDWR | O_CREAT | O_EXCL, S_IRWXU | S_IRWXG | S_IRWXO);

The calls don't fail (I check them) and indeed one process who fork / exec s other processes creates them and the other processes do share the memory and semaphores and there is proper synchronization.调用不会失败(我检查它们)并且确实有一个进程fork / exec的其他进程创建它们,而其他进程确实共享内存和信号量,并且有适当的同步。

When I use the ipcs command however, I don't see the shared memory nor the semaphore.但是,当我使用ipcs命令时,我看不到共享内存和信号量。 Why is that?这是为什么? If they don't appear with ipcs , where can I check them?如果它们没有与ipcs出现,我可以在哪里检查它们?


In my ipcs output I don't have any entries in the Semaphore Array list and the ones in shared memory are related to skype, firefox and plugin-container (of firefox).在我的ipcs输出中,信号量数组列表中没有任何条目,共享内存中的条目与 Skype、firefox 和插件容器(firefox 的)相关。 I checked them with我检查了他们

grep shmid /proc/*/maps     # observe pid
readlink /proc/pid/exe

Ipcs reports only System V shared memory. Ipcs 仅报告 System V 共享内存。 You must be using Posix shared memory.您必须使用 Posix 共享内存。 Apparently these are two completely different mechanisms.显然这是两种完全不同的机制。 Posix shm is shown under /dev/shm. Posix shm 显示在 /dev/shm 下。

I've had the same issue, and the accepted answer is not satisfying enough as it is not explaining why this is happening.我遇到了同样的问题,接受的答案不够令人满意,因为它没有解释为什么会发生这种情况。 I found the answer in another similar question: i cannot see the shared memory created by the boost::interprocess via shell command ipcs我在另一个类似的问题中找到了答案: 我看不到 boost::interprocess 通过 shell 命令 ipcs 创建的共享内存

"As far as I'm aware, ipcs reports only System V shared memory. POSIX shared memory is a separate area, and has to be queried separately. On linux systems, check /dev/shm." “据我所知,ipcs 只报告 System V 共享内存。POSIX 共享内存是一个单独的区域,必须单独查询。在 linux 系统上,检查 /dev/shm。”

One solution I just found was that shared memory and shared semaphores are listed under:我刚刚发现的一种解决方案是共享内存和共享信号量列在下面:

/dev/shm

The files there are useful for knowing what shared objects there are and maybe to unlink them, but they don't provide any useful information beyond that (as ipcs does).那里的文件对于了解有哪些共享对象以及unlink它们很有用,但除此之外,它们不提供任何有用的信息(如ipcs所做的那样)。

就我而言,解决方案是使用sudo

sudo ipcs -m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM