9

This may sound like a silly question but up until recently if you tried to unmount a volume that was in use the Finder reported that it was in use, but not by whom. This is simple Unix functionality, if a file is open on a mount point, do not allow it to eject. But now they seem to have added functionality that lets the user know what programs are currently using a mounted system, and I have been looking through man pages of fopen,stat, etc. for Unix like operating systems(distros of linux) and I can't seem to find similar functionality.

Is this functionality specialized, or am I just looking in the wrong place?

awiebe
  • 3,758
  • 4
  • 22
  • 33

3 Answers3

5

There are BSD-level calls (mainly lsof, whose source is at http://www.opensource.apple.com/source/lsof/) that let you examine the list of files open in a process. Activity Monitor, for example, uses them.

Using lsof as a starting point, you can iterate through processes and see if any of them are using a file under the mount point you're examining. There may be more efficient ways to do it though, of which I'm not aware. :)

Jonathan Grynspan
  • 43,286
  • 8
  • 74
  • 104
  • Lsof revision 4.82 lists on its standard output file information about files opened by processes for the following UNIX dialects: AIX 5.3 FreeBSD 4.9 for x86-based systems FreeBSD 7.[01] and 8.0 for AMD64-based systems Linux 2.1.72 and above for x86-based systems Mac OS X 10.[56] for Intel and PowerPC systems Solaris 9 and 10 – awiebe Nov 11 '11 at 04:18
  • Okay? Sounds like you're covered. – Jonathan Grynspan Nov 11 '11 at 18:09
0

It's somewhat specialized. Check out the lsof utility.

0

Check the man page for fuser, and run fuser -c /mountpoint

andrew
  • 1