我通过在OS中使用shm_open/mmap分配共享内存段,在父进程和多个子进程之间共享内存。我的理解是,父级必须在每个段上调用shm_unlink,否则共享内存就会永久泄漏。
在阅读文档时,我最初的想法是,当没有一个具有映射的进程存在时,共享段就会被清理。然而,实验表明情况并非如此,必须有人显式地使用shm_unlink。
在OS中有任何方法来列出当前所有现有的共享内存段吗?,问题是父程序可能崩溃,因此没有机会调用shm_unlink。在Linux中,我的解决方案是清除/dev/shm,但在OS中,我需要某种方式列出打开的共享段。
发布于 2014-11-29 08:52:04
答案似乎是:你不能。
首先,请参阅这个问题,它引用了内核中的一个注释:
还可以在Apple邮件列表unix移植上看到这个帖子:
There is no "picps"/"picprm" utility, you are expected to remember what
you create and clean up afterward, or clean up first thing on
restart if you crash a lot, there is nothing exposed directly
in the filesystem namespace, and you are expected to do
the shm_unlink because it is a rendezvous for potentially a
lot of unrelated programs.发布于 2014-03-03 17:45:20
希望你能解决你的问题。您可以使用ipcs -a并在NATTCH的标题下查看共享内存。该值将告诉您有多少共享内存段附加到特定的id。
https://stackoverflow.com/questions/18855230
复制相似问题