Loading
Nov 04, 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
Trending Topics
| You Need A Budget | Feb 10, 2012 |
| The Linux powered LAN Gaming House | Feb 08, 2012 |
| Creating a vDSO: the Colonel's Other Chicken | Feb 06, 2012 |
| Your CMS Is Not Your Web Site | Feb 01, 2012 |
| Casper, the Friendly (and Persistent) Ghost | Jan 31, 2012 |
| Razor-qt 0.4 - Qt based Desktop Environment | Jan 30, 2012 |
- Linux-Based X Terminals with XDMCP
- Readers' Choice Awards 2011
- 100% disappointed with the decision to go all digital.
- Parallel Programming with NVIDIA CUDA
- You Need A Budget
- Validate an E-Mail Address with PHP, the Right Way
- Python for Android
- The Linux powered LAN Gaming House
- The Linux RAID-1, 4, 5 Code
- RSS Feeds
- Gnome3 is such a POS. No one
1 hour 25 min ago - Gnome 3 is the biggest POS
1 hour 35 min ago - I didn't knew this thing by
7 hours 40 min ago - Author's reply
11 hours 4 min ago - Link to modlys
12 hours 11 min ago - I use YNAB because of the
12 hours 22 min ago - Search
17 hours 25 min ago - Question
17 hours 48 min ago - for the record
17 hours 51 min ago - That's disappointing. Thanks
20 hours 14 min ago





Comments
That's crazy! but what the hey, sometimes we're lazy :)
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
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?
lsof is NOT slow at all.
lsof is NOT slow at all.
I believe there would be other problems with your machine.
A very powerful command
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
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
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!
Thanks! That's a cool trick!
Thanks, a much needed tip.
Thanks, a much needed tip.
Nice tip
Thanks for the gr8 tip.
Short and to the point
Short and to the point Howto. Nice.
Don't forget fuser!
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
You can also use the "lazy umount" - see http://aplawrence.com/Linux/lazy-unmount.html for examples.