I have two windows open on the same machine (Ubuntu 9, ia32, server). I'll call these windows W1 and W2.
W1:
$ cd ~/test
$ ls
sample
$
In W2 I run "make" from a parent directory that recreates file test/sample:
$ make project
.
.
$ cd test
$ ls
sample
$
Now, returning to W1:
$ ls
$ cd ../test
$ ls
sample
$
In other words, after I build from another window and the file test/sample is replaced, ls shows the file as missing in the 2nd window until I cd ../test
back into the directory whereupon it reappears.
I can give more details if required, but just wondering if this is a well-known behavior.
Do this experiment, and you'll see what's going on:
Basically, when the working directory a process is in is removed the system can't just randomly change its working directory for it. That would be a huge security hole. So it gives it sort of a fake working directory that can be read (giving 0 bytes) and various other operations, but cannot largely be used. It will happen to have the same name as a new directory created in the same place, but that's superficial.
If you do
lsof | fgrep $$
after the directory is removed you will see an entry like this:You have (resp. your shell has) a file descriptor open to a directory whose nlink count has been reduced to zero (probably — you left out the most important trace of all: from make) — but of course the object lives on as long as a reference is held:
Recreating /dev/shm/z creates a new entity.
All well-defined behavior.