I'm running OS X 10.6 Server, and I want to eject my external drive so I can do some disk maintenance such as defraging it. However when I try to eject the drive it fails saying the disk is in use. I can force eject it but that could cause corruption... How can I tell which application is using the drive and holding it open?
Asked
Active
Viewed 5.1k times
3 Answers
65
Try sudo lsof | grep /Volumes/External, where "External" would be the name of your external drive. Are you hosting any services' data off of that drive?
churnd
- 4,237
8
lsof - List of open files
At your command promt just type sudo lsof to see a list of open files and their location and process id so that you can kill the process.
To refine it a little bit you could use sudo lsof | grep hard drive name.
Once you have the pid sudo kill -9 pid to kill the naughty process.
Jon Rhoades
- 5,047
0
Use this cmdline to find the processes access to your drive:
sudo lsof | grep -v -e"^COMMAND" | grep -i YOUR_DRIVE_NAME | sort -u -k 1,2 | perl -n -e's/^\w+\s+(\d+).*/ps -p $1/; print $_'
Gerd
- 101