1

I did some search but didn't find similar questions. Here is my steps:

  1. copy a file to /dev/shm (tmpfs)
  2. mmap that file with lock
  3. read data from that file
  4. delete the file

After step 4, the previous loaded data is still available, why? Thanks in advance

user3126461
  • 152
  • 8

1 Answers1

1

On Unix, a file's data is not deleted until every remaining process closes/munmaps it.

Since you've opened the file and have an active handle or mapping to it, you can continue reading and writing the file data for as long as you want. It will not be freed until after you close it.

that other guy
  • 116,971
  • 11
  • 170
  • 194
  • But it does disappear from the tmpfs system, and the data is still there in the memory, how's that happened? – user3126461 Aug 13 '18 at 20:20
  • 1
    The file data still exists in the filesystem, it's just not accessible via a filename anymore. This is like how you can reset a C++ `shared_ptr` without affecting the object in RAM, as long as something else is keeping it alive. – that other guy Aug 13 '18 at 20:32