List Open Files
November 4th, 2008 by Jagadish Kavuturu in
If you try to unmount a partition and get a message like this:
# umount /media/usbdisk/ umount: /media/usbdisk: device is busy
use the lsof command to find out what programs are using what files:
# lsof /media/usbdisk/ COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME bash 6925 root cwd DIR 8,17 4096 1 /media/usbdisk/ xmms 6979 root cwd DIR 8,17 4096 1 /media/usbdisk/
This shows that the programs bash and xmms are using the device. For an even clearer picture, use the device name rather than the mountpoint:
# lsof /dev/sdb1 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME bash 6925 root cwd DIR 8,17 4096 1 /media/usbdisk xmms 6979 root cwd DIR 8,17 4096 1 /media/usbdisk xmms 6979 root 8r REG 8,17 2713101 377 /media/usbdisk/a.mp3
You either can wait until those processes exit or terminate them manually.
__________________________
Jagadish Kavuturu
Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer
Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.
Subscribe now!
The Latest
Newsletter
Tech Tip Videos
- Nov-04-09
- Oct-29-09
- Oct-26-09
Recently Popular
From the Magazine
December 2009, #188
If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.
Delicious
Digg
StumbleUpon
Reddit
Facebook








That's crazy! but what the hey, sometimes we're lazy :)
On November 19th, 2008 maskedfrog says:
Thanx for the tip Anthony,
THAT will come in handy. The times I've waited for a cd to umount
and waited...and waited...and gave up and rebooted :-(
More apt to use in the examples shown though, waiting for a process to finish and don't want to forget to umount so just do it the "lazy" way.
Uptimes should shoot thru the roof now :-))
Slow
On November 15th, 2008 Hatta (not verified) says:
In my experience 'lsof' is extremely slow. So slow that I can log off and log back on before I'd expect lsof to finish. Are there any tricks to speed it up to the point that it's usable?
A very powerful command
On November 10th, 2008 SteveC (not verified) says:
The lsof command is far more powerful than the article implies. It's worth spending some time reading the documentation. My most common use is to locate connections with the -i option:
Killing with fuser
On November 10th, 2008 Anonymous (not verified) says:
If
lsof +D [device]
shows nothing
you can use
fuser -m [device]
to show processes that say that are using the device.
and you can use
fuser -km [device]
to directly kill them all
Doesn't always work
On November 7th, 2008 Ivan V (not verified) says:
Unfortunately, many times, neither lsof nor fuser have worked for me (the device says busy but nothing comes up)...
The only solution in those cases is for me to logoff or try to find a possible culprit.
Thanks! That's a cool trick!
On November 6th, 2008 Durand (not verified) says:
Thanks! That's a cool trick!
Thanks, a much needed tip.
On November 6th, 2008 Anonymous (not verified) says:
Thanks, a much needed tip.
Nice tip
On November 6th, 2008 vinit (not verified) says:
Thanks for the gr8 tip.
Short and to the point
On November 5th, 2008 Anonymous (not verified) says:
Short and to the point Howto. Nice.
Don't forget fuser!
On November 4th, 2008 Devin (not verified) says:
You can also use fuser if you know which directory or file is open and you want to find the offending process.
fuser [file]
You can also use the "lazy
On November 4th, 2008 Anthony Lawrence (not verified) says:
You can also use the "lazy umount" - see http://aplawrence.com/Linux/lazy-unmount.html for examples.
Post new comment