Try the fuser command.
The man page for fuser states:
fuser Command
Purpose
Identifies processes using a file or file structure.
Syntax
fuser [ -c | -d | -f ] [ -k ] [ -u ] [ -x ] [ -V ]File ...
Description
The fuser command lists the process numbers of local processes that use the local or remote files specified by the File parameter. For block special devices, the command lists the processes that use any file on that device.
Each process number is followed by a letter indicating how the process uses the file:
c Uses the file as the current directory.
e Uses the file as a program's executable object.
r Uses the file as the root directory.
s Uses the file as a shared library (or other loadable object).
The process numbers are written to standard output in a line with spaces between process numbers. A new line character is written to standard error after the last output for each file operand. All other output is written to standard error.
Flags
-c Reports on any open files in the file system containing File.
-d Implies the use of the -c and -x flags. Reports on any open files which have been unlinked from the file system (deleted from the parent directory). When used in conjunction with the -V flag, it also reports the inode number and size of the deleted file.
-f Reports on open instances of File only.
-k Sends the SIGKILL signal to each local process. Only the root user can kill aprocess of another user.
-u Provides the login name for local processes in parentheses after the process number.
-V Provides verbose output.
-x Used in conjunction with -c or -f, reports on executable and loadable objects in addition to the standard fuser output.
So you may not need to write something more than a wrapper around fuser for the file in question. I hope this helps. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)