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 4.0k times
3 Answers
50
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,077
- 5
- 34
- 42
-
Just some shared folders, but I know that all the clients on the network had ejected those shares and the entire server. – jamone Jul 12 '10 at 11:59
-
1Doesn't always matter. Sometimes the AFP/SMB/NFS/FTP/etc processes will leave open files just because the service is running. Best bet is to try to stop the service, then eject. That would be better than using the above command along with `kill -9`. You can stop a service via command line by something like `sudo serveradmin stop smb`, then start it by `sudo serveradmin start smb`, where "smb" is the name of the service. `sudo serveradmin list` will show them all. – churnd Jul 12 '10 at 15:37
-
1Normally it's Spotlight indexing stuff! – JGFMK May 03 '19 at 23:36
-
For me, the culprit seems to consistently be Photos.app's `photoanalysisd`. You can use this command to kill `photoanalysisd` to enable ejection of the drive: `launchctl kill -TERM gui/$UID/com.apple.photoanalysisd` – rinogo Sep 26 '21 at 20:46
6
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
- 4,987
- 3
- 31
- 48
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
- 3