Article 59D4D Detection of dangling file handles/FDs

Detection of dangling file handles/FDs

by
quiret
from LinuxQuestions.org on (#59D4D)
Dear linux developers,

let's assume I have a file called /media/quiret/INTENSO/test.txt. My program opens a fd to it using open("/media/quiret/INTENSO/test.txt", O_RDONLY ). The folder /media/quiret/INTENSO/ is actually my USB drive. Then I forget the worries of the world and plug out my USB drive while the FD is open in my program. Now I have several questions:

1. can my program detect that the file is missing after the atomic call to read/write/etc?
2. how does Linux read data from the file if the file has no links?
3. how long does a fd stay valid for file operations if it has no more links? and when does the first error get returned by any FS syscall?

Thank you for your time!

- quiret/rplgn/The_GTAlatest?d=yIl2AUoC8zA latest?i=1s_tc3ERsUU:rzgDS-yHUjo:F7zBnMy latest?i=1s_tc3ERsUU:rzgDS-yHUjo:V_sGLiP latest?d=qj6IDK7rITs latest?i=1s_tc3ERsUU:rzgDS-yHUjo:gIN9vFw1s_tc3ERsUU
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments