How to find out when a file opened by another process was closed ?

Saturday, October 09 2004 @ 11:09 PM UTC

Contributed by: unix

If we need to wait another process has finished working with a file, how can we be notified when the process closed the file ?

In Terminal, type

man lsof

lsof is installed in Mac OS X, but if you want to look at the source code, it's available here, also of interest see (topics 2.4 and 2.6)

Example of use:
we are waiting for MS-Word to close a file named Form.doc opened in the /tmp directory with:
lsof +D /tmp | grep Form.doc
As usual, such a command is easily "piped" or even executed from an AppleScript using do shell script.