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

Sunday, October 10 2004 @ 12:09 AM BST

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.