View Full Version : Check if mounted volume is in use? / what it's in use by?

noire anqa
Dec 4, 2010, 04:53 AM
Hi, anyone know how i get a list of programs that are currently accessing a volume?

Backstory: I'm using an encrypted sparsebundle to store sensitive documents, and backing up using time machine. Time machine will back up a sparsebundle, even if it's mounted - this corrupts the backup and leaves the backup of the encrypted image unmountable. (Which i imagine is why filevault won't backup when logged in).

To remedy this i'll programatically change the timemachine backup list:

If nothing is using the sparsebundle i want it to unmount the sparsebundle before initiating a backup, and reattach it when it's done.

If im using a file on the sparsebundle i want it to backup everything but the sparsebundle.

However, if i'm using a file in the bundle, but i havent been at the computer for more than an hour, i want to know what programs are blocking the bundle from ejecting, send them applescript "save your work and quit" commands, and backup the sparsebundle.

For this i'll need a list of the programs accessing files on the sparsebundle! diskutil only says the device is busy without elaborating on what programs are using it. Finder however knows exactly what's using it, how does it do it?


Dec 4, 2010, 08:00 AM
man lsof

It should be able to give you what you want.


Dec 4, 2010, 08:05 AM
Hi, anyone know how i get a list of programs that are currently accessing a volume?

lsof|grep /Path_to_mounted_Volume

noire anqa
Dec 4, 2010, 09:39 AM
Ah that's great, thank you both!

Dec 4, 2010, 02:09 PM
Note that on Mac OS X 10.6 at least, you can ditch grep and just call it as.

lsof /Path_to_mounted_Volume

If a name is the mounted-on directory of a file system or the device of the file system, lsof will list all the files open on the file system. To be considered a file system, the name must match a mounted-on directory name in mount(8) output, or match the name of a block device associated with a mounted-on directory name. The +|-f option may be used to force lsof to consider a name a file system identifier (+f) or a simple file (-f).