c++ - df 报告磁盘使用情况但共享内存/dev/shm 中没有文件

标签 c++ linux posix shared-memory

我正在尝试使用共享内存/C++ 进行编程。我有多个进程访问一个共享内存块,然后在执行期间取消链接,并在完成前一个 block 后链接到另一个 block 。

一切正常,除了,当我列出 ls/dev/shm 时它是空的,但是当我 df/dev/shm 时它说空间已消耗,这是为什么?

最佳答案

如果您正在使用 shm_unlik(),请记住 shm_unlik:

"remove the name of the shared memory object named by the string pointed to by name."

但是

"the removal of the memory object contents shall be postponed until all open and map references to the shared memory object have been removed."

(如 man page 中所述)

因此,您可能使用 ls 看不到任何内容,但您仍然看到使用 df 占用的内存。

关于c++ - df 报告磁盘使用情况但共享内存/dev/shm 中没有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33344180/

相关文章:

c++ - 如何在 Xcode 中链接动态库?

c++ - 四元数到方向 vector

c - connect() 会阻塞 TCP 套接字吗?

c++ - 如何禁止任何应用程序的所有线程在特定 CPU 核心上运行,除非我指定的线程?

c++ - 如何将 DWORD 和 LPBYTE 解析为 std::string

c++ - 使用 QImageWriter 压缩 DDS 图像

linux - 哪些 Linux 命令可以解析每行有两个定界符的文件?

c# - 在 Linux 上从 .NET Core 手动调用 recvmsg 不会返回

C++ 错误 : undefined reference to 'clock_gettime' and 'clock_settime'

c++ - fork 进程一直监听服务器的端口