1

Under Linux Kernel, Lets say we have two process (p1 and p2) reading same file (/file.txt)

If im not wrong, there will be an task_struct pointing to files_struct which in-turns points to an entry in file (file table).

file table reference count will be incremented if the file /file.txt opened by other process (p2). when we delete a file /file.txt (via process3), since the reference_count > 0. We can access the file content from process1 and process2.

What happens when p1 and p2 closes the file. How exactly kernel finds out it needs to deleted rather than normal use-case.

webminal.org
  • 44,948
  • 37
  • 94
  • 125
  • 1
    This should answer most of you question [link](http://stackoverflow.com/questions/2028874/what-happens-to-an-open-file-handler-on-linux-if-the-pointed-file-gets-moved-de). As long as process (p1 and p2) has a open file descriptor, they can still read/write the data blocks associated with the file. P3 can mark the file for deletion (when proper locking on taken by the process), which would internally update the bitmap/FS metadata and directory entry to mark the file for deletion. Its best to look into the `unlink()` operation specific to the file system implementation. – askb Nov 18 '14 at 06:17

0 Answers0