c++linuxposixshared-memory

df reports disk usage but no files in shared memory /dev/shm


I'm trying to program using shared memory/c++. I have multiple processes accessing a shared memory piece, which then unlinks during the execution and links to another piece once it's done with the previous piece.

All works, except, when i list ls /dev/shm it is empty, but when i df /dev/shm it says space consumed, why is it?


Solution

  • If you are using shm_unlink(), keep in mind that shm_unlink():

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

    but

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

    (as stated in the man page)

    Thus it is possible that you don't see anything with ls but you still see the memory as occupied by using df.