Check if mounted volume is in use? / what it's in use by?

Discussion in 'Mac Programming' started by noire anqa, Dec 4, 2010.

  1. noire anqa, Dec 4, 2010
    Last edited: Dec 4, 2010

    macrumors regular

    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?

  2. Moderator


    Staff Member

    man lsof
    It should be able to give you what you want.

  3. macrumors member

    lsof|grep /Path_to_mounted_Volume
  4. macrumors regular

    Ah that's great, thank you both!
  5. Moderator


    Staff Member

    Note that on Mac OS X 10.6 at least, you can ditch grep and just call it as.

    lsof [I]/Path_to_mounted_Volume[/I]


Share This Page