Weird CLI behaviour.

Ken D'Ambrosio ken at jots.org
Mon Feb 10 21:24:13 UTC 2020


On 2020-02-10 16:09, Ken D'Ambrosio wrote:

> Bottom line: there's a /tmp/foobar that the system generally knows about, and there's a /tmp/foobar that *only my bash session* knows about.  This is not a bug, but is expected behavior for deleted-but-not-reaped files/directories. 
> 
> -Ken

Extra fun for those playing at home: you can *see* this directory by
cheating some: 

First, we go and ask lsof for files open by bash with name foobar; then
we look at the /proc filesystem to show us the cwd for that process: 

ken at strider:/tmp/foobar (QA)$ lsof | grep bash | grep foobar
bash 8330 ken cwd DIR 0,28 0 1412320 /tmp/foobar (deleted)
ken at strider:/tmp/foobar (QA)$ ls -al /proc/8330/cwd
lrwxrwxrwx 1 ken ken 0 Feb 10 16:15 /proc/8330/cwd -> '/tmp/foobar
(deleted)' 

(Note you can actually ls the directory -- since I've got nothing in it,
I get nothing back: 

ken at strider:/tmp/foobar (QA)$ ls
ken at strider:/tmp/foobar (QA)$ ls /proc/8330/cwd
ken at strider:/tmp/foobar (QA)$ 

Now, I'm going to cd to /tmp/foobar -- which is the "new", extant,
undeleted directory (which has a file with the date in it that I created
in the last e-mail), and repeat the exact same steps as above: 

ken at strider:/tmp/foobar (QA)$ cd /tmp/foobar
ken at strider:/tmp/foobar (QA)$ ls
date file
ken at strider:/tmp/foobar (QA)$ ls /proc/8330/cwd
date file 

E voila!  There's your stuff -- and the old directory, now that the
refcount has dropped to zero, has been reaped: 

ken at strider:/tmp/foobar (QA)$ lsof | grep /tmp/foobar | grep bash
bash 8330 ken cwd DIR 0,28 16 1412321 /tmp/foobar
ken at strider:/tmp/foobar (QA)$ 

-Ken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20200210/bb4618cb/attachment.html>


More information about the ubuntu-users mailing list