Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm on current OS X 10.7. Sometimes I want to check which application locks a certain file. I do that by

lsof | grep $FILENAME

I noticed that running this command invokes two instances of lsof. Why is that?

share|improve this question
Tip: lsof $FILENAME is faster. – grawity Jun 25 '12 at 20:45
Thanks, but using grep enables me to find open files by only parts of its name. – Max Ried Jun 25 '12 at 20:47
up vote 4 down vote accepted

lsof does this internally to avoid deadlocking. If it has to perform an operation that may deadlock, it performs in it an auxiliary process. If the operation deadlocks, it can kill the auxiliary process. It is documented in the manual:

Lsof can be blocked by some kernel functions that it uses - lstat(2), readlink(2), and stat(2). These functions are stalled in the kernel, for example, when the hosts where mounted NFS file systems reside become inaccessible.

Lsof attempts to break these blocks with timers and child processes, ...

share|improve this answer
Sounds like a dirty hack :/ – Max Ried Jun 25 '12 at 20:51
Absolutely. That could be said of NFS, actually. – David Schwartz Jun 25 '12 at 20:51
Wow, sometimes I'm desperately wondering why we chose to let such systems run our society... – Max Ried Jun 25 '12 at 20:55
@MaxRied: The hard,nointr mode of NFS and other network file systems was added intentionally, as it can be useful: it prevents programs from thinking that all files suddenly disappeared if, say, the rootfs / was NFS-mounted and the server went down for a moment. There are, however, soft and intr mount options, which will cause requests to time out & make them interruptible. – grawity Jun 25 '12 at 21:17
@MaxRied: If you start asking questions like "Who would add them?" and "What would they add them to?" you start to see that there's no one place to fix this. Unfortunately, non-blocking operations or operations with timeouts were never part of the standard API and so they're missing from the whole chain all the way from userspace through the C file API, through the kernel, across the NFS protocol, back to the file server, and then the server's kernel filesystem API that the NFS server code uses. – David Schwartz Jun 26 '12 at 6:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.