When using the Mac OS X UI to eject an external hard drive, I occasionally get this error: ‘The disk “[volume name]” is in use and could not be ejected. \ Try quitting applications and try again.” Only mac won’t tell me which applications are using this drive. I hopelessly try to kill applications by force quitting or even using activity monitor to zap processes.
I think I have finally solved this.
Open up the program called Terminal.app (located in Applications/Utilities). Enter the following replacing [name of drive] with the name of your hard drive:
sudo lsof +D "/Volumes/[name of drive]"
You should get a list that looks something like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 637 ajx cwd DIR 14,2 442 2993107 /Volumes/path/to/file/in/use
preview 638 ajx cwd DIR 14,2 442 2993107 /Volumes/path/to/file/in/use
...
These are the applications/processes that are using your hard drive. They must be killed (quit) before you eject it safely.
Try to quit any applications you recognize the normal way. For each of the other processes (line items) you want to issue the kill command followed by that process’s PID. You might get errors in which case for each PID try the following until you don’t get an error. You can always run the lsof command again to see if the process really died.
kill [PID of process]
sudo kill [PID of process]
sudo kill -INT [PID of process]
sudo kill -KILL [PID of process]
Update: So it seems sometimes lsof will just hang… I don’t know what to do in this case, hopefully I will update again with further solutions.
Tags: 10.4, 10.5, eject, external hard drive, kill, lsof, mac os x
Just seen this as am having a problem trying to eject my 8GB memory stick having transferred my iPhotos temporarily. Have permanently running ‘catherine wheel’
Cannot do as you recommend because unable to access Applications due to catherine wheel precluding active cursor!!
Running 10.6.2
Just came across this solution – works perfectly! I was able to figure out which (one) app was accessing my disk…something I set up when I first installed the app months ago and then completely forgot about. Took care of that and the drive ejected with no problem. Thank you!!