List Open Files
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
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Designing Electronics with Linux
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Dynamic DNS—an Object Lesson in Problem Solving
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Using Salt Stack and Vagrant for Drupal Development
- Reply to comment | Linux Journal
2 hours 41 min ago - Dynamic DNS
3 hours 15 min ago - Reply to comment | Linux Journal
4 hours 14 min ago - Reply to comment | Linux Journal
5 hours 4 min ago - Not free anymore
9 hours 6 min ago - Great
12 hours 53 min ago - Reply to comment | Linux Journal
13 hours 1 min ago - Understanding the Linux Kernel
15 hours 16 min ago - General
17 hours 46 min ago - Kernel Problem
1 day 3 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



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.