Saturday, March 01, 2008

Quick way to detect which process is blocking a mountpoint

All to often when you want to unmount something you get this little error message as response:

$ umount /mnt
umount: /mnt: device is busy

Not exactly very helpful. A call to fuser or lsof doesn't work very well either. Not sure what is wrong with fuser, but sometimes it simply doesn't report a proper answer even so the device is busy. lsof on the other side works, but is very very slow, it simply not fun to use. Luckily there is a quick workaround:

$ ls -l /proc/*/cwd 2> /dev/null | grep -i mnt
lrwxrwxrwx 1 ingo ingo 0 2008-03-02 03:20 /proc/6828/cwd -> /mnt

This gives you the process blocking a directory pretty much instantly. The 6828 here is the process id which you can then kill or force to another working directory. This of course only checks for the current working directory, not all open files, but for most cases this is really all you need.

There is of course also 'umount -l' which will "unmount" something even if it is blocked, the trouble with that is that it won't actually unmount anything, it will just look like that, so a DVD still won't eject when using 'umount -l' until the blocking process is actually gone.

PS: It is kind of surprising that Linux CD/DVD handling still sucks as bad as it did 10 years ago.

1 comment:

maniel said...

you can use lsof for that