I was able to reproduce and analyze this behaviour on a debian system.
The reason for this, in my experiments, is, that changing the content of the file while it is opened within Julia, e.g. with vim, does not only change the file, but deletes it and writes a new version. The deletion just deletes the inode to the original data, whereas the file descriptor opened within Julia still points to the original data on the filesystem which still exists. The changed data (the new test.txt) is now saved at a different place on the filesystem and test.txt is a new inode to the new data.
if any process has the file open when this happens, deletion is postponed until all processes have closed the file
Deleting Files (The GNU C Library)
See the following:
julia> filepath = "test.txt"; io = open(filepath, read=true, append=true);
julia> seekstart(io);read(io, String)
"test\n"
Now we change in another shell the file test.txt and see what happens to the file descriptor:
root:~# ps -efl | grep julia | grep -v grep
4 S root 1001 29194 10 80 0 - 125484 ep_pol 12:30 pts/1 00:00:00 julia-1.5.3/bin/julia
pid of our julia process is 1001 :
root:~# ll /proc/1001/fd/
...
lrwx------ 1 root root 64 Jan 15 12:31 20 -> /root/test.txt
...
You see an open file descriptor called 20
which points to the open file (and some more which I have removed here).
Now we edit the content of the file with vim and save it, now we get:
root:~# ll /proc/1001/fd/
...
lrwx------ 1 root root 64 Jan 15 12:31 20 -> (deleted)/root/test.txt~
...
Which means, the original file, the one which is still opened in Julia, has been deleted and what is left is a symbolic link to the original place of the (unchanged) data on the filesystem.
You can try to edit /proc/1001/fd/20 (the 20 is my special case, you will have some other name) and you will see these changes reflected with the Julia command.
Ok, lets check, what happens, if we don’t change the file with an editor, but just append some data:
julia> close(io)
julia> filepath = "test.txt"; io = open(filepath, read=true, append=true);
julia> seekstart(io);read(io, String)
"test\n"
Second shell:
root:~# ll /proc/1001/fd/
...
lrwx------ 1 root root 64 Jan 15 12:31 20 -> /root/test.txt
...
root:~# echo "123" >> test.txt
root:~# ll /proc/1001/fd/
...
lrwx------ 1 root root 64 Jan 15 12:31 20 -> /root/test.txt
...
julia> seekstart(io);read(io, String)
"test\n123\n"
Voila, changes show up.
Of course, Windows is behaving differently, so it couldn’t be reproduced. What Linux (Arch) does, I don’t know, but apparently also something else or @jling didn’t edit with an editor.
The complete story is quite complex and can be searched with keywords: “linux delete unlink inodes”.