Skip to content
Prev 366573 / 398502 Next

[FORGED] file.exists() on device files

On 11/01/17 23:12, Benjamin Tyner wrote:
(a) Exactly the same thing happens to me (I am also running Ubuntu 16.04).

(b) Things get a bit confused because /dev/fd is actually a symbolic link:
(c) But then doing
Gives the same result as before:
(d) It turns out that the four "files" in /proc/self/fd are again
symbolic links:
(e) But now do it again!!!
Different number; 7154 rather than 7150.

(f) The name "/proc" would seem to imply that this has something to do 
with processes; the directories "7150", "7154" etc. are being created 
and removed on the fly, as a result of some process (presumably the "ls"
process) starting and finishing.

I have no insight into what is being effected here, or what is really 
going on "deep down", but the foregoing is some sort of "explanation".
By the time file.exists() is invoked, the ls process called by 
list.files() has finished and the associated directory (e.g. "7150", 
"7154", ...) has ceased to be.

What you do with this "explanation" is up to you.  My advice would be to 
forget about it and go to the pub! :-)

cheers,

Rolf Turner