I seem to run into this quite a bit, and it regularly ticks me off. My biggest causes:
- documents open in editors (some editors lock files while open, others do not)
- a Terminal window CD'd to a directory on the device (I don't understand why this locks it)
- spotlight (MDWorker) is indexing it (recently spotlight has gotten much better at yielding and allowing ejects)
- Finder (for NO obvious reason, requiring a force-quit of Finder)
- hdiutil (for having a disk image opened that's saved on the volume I am trying to eject) Again this one has gotten better, I've seen these domino eject as many as three levels deep automatically on some occasions, and on other occasions I had to eject something manually.

In the end, I usually end up cracking open a terminal window to see who the guilty party is using LSOF. I have the exact same issues with trying to empty the trash when a locked file is in the can. Lets say I have a file XYZ123 or a volume XYZ123 that I can't eject/empty. In terminal:

lsof -nP | grep -i XYZ
Finder 1075 virtual1 16u REG 1,4 113904 132265544 /.Trashes/501/XYZ123.doc

lsof -nP | grep -i XYZ
hdiutil 1075 virtual1 16u REG 1,4 113904 132265544 /Users/virtual1/Desktop/XYZ123.dmg


If the image is mounted, it's probably best to find another way to dismount it or get Finder to do a "force eject". If some app has a document open for no good reason, you can just quit the app. If it's a hidden process (like mdworker) you can kill it with the KILL command to allow eject.

kill 1075
process terminated.

Spotlight can be annoying. It'll insta-respawn the worker and pick up right where it left off a lot of the time. Sometimes the only way to kick that particular dog is go into spotlight's privacy and privatize where the file is (even if only long enough to deal with the file)


I work for the Department of Redundancy Department