in reply to Re^6: How to detect if file is in use?
in thread How to detect if file is in use?

I thought this was interesting ... so I expanded it just a wee bit:

$ (cd /tmp; perl -e 'symlink("foo","bar") or die $!; open F, ">bar" or + die $!; rename "foo", "blah" or die $!; print readlink("/proc/$$/fd/ +".fileno(F)),$/'; rm blah bar) /tmp/blah
As should be expected(?), it follows renames. And, quite interestingly ...
$ (cd /tmp; perl -e 'symlink("foo","bar") or die $!; open F, ">bar" or + die $!; unlink "foo" or die $!; print readlink("/proc/$$/fd/".fileno +(F)),$/'; rm bar) /tmp/foo (deleted)
Wow. That's cool. Imagine the abuse one could wreak on a poor programmer by creating a file "/tmp/foo \(deleted\)" :-) I suppose that testing for the file being deleted means actually testing the symlink via stat (e.g., -e).