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

    Joined:
    Aug 20, 2010
    #1
    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?

    Thanks
     
  2. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    Code:
    man lsof
    It should be able to give you what you want.

    B
     
  3. macrumors member

    Joined:
    Aug 28, 2008
    #3
    Try
    Code:
    lsof|grep /Path_to_mounted_Volume
     
  4. thread starter macrumors regular

    Joined:
    Aug 20, 2010
  5. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #5
    Note that on Mac OS X 10.6 at least, you can ditch grep and just call it as.

    Code:
    lsof [I]/Path_to_mounted_Volume[/I]

    B
     

Share This Page