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?
3 Answers
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?
-
Just some shared folders, but I know that all the clients on the network had ejected those shares and the entire server.– jamoneJul 12, 2010 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 likesudo serveradmin stop smb
, then start it bysudo serveradmin start smb
, where "smb" is the name of the service.sudo serveradmin list
will show them all.– churndJul 12, 2010 at 15:37 -
1
-
For me, the culprit seems to consistently be Photos.app's
photoanalysisd
. You can use this command to killphotoanalysisd
to enable ejection of the drive:launchctl kill -TERM gui/$UID/com.apple.photoanalysisd
– rinogoSep 26, 2021 at 20:46
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.
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 $_'