How determine if a file is opened by another process

uunet!bria!mike uunet!bria!mike
Thu Jan 31 11:45:30 AEST 1991


In an article, calvin.doc.ca!andrew (Andrew Patrick) writes:
>I need to know if there's a standard, *safe* way for a process to
>find out if some other process (any other process on the machine)
>has a specific file open at the time of the query. [...]
>Oh yes.  The machine is an Encore Multimax 520, running UMax V (a
>System V based UNIX-alike).  I do know about the dodge of reading
>/dev/kmem, and the Multimax has a special call to get the address of
>the inode table, to make it a little safer, but I'd like to avoid
>this.  The program which needs this info would then have to be
>setuid root, or /dev/kmem would have to be opened for general read
>access, which we want to avoid if at all possible.

There is no portable way to get the information that you want; poking
through the kernel is the only way I know of determining if some
unrelated and/or non-cooperative process has a file open.  If you're worried
about security issues (as well you should be), then one solution would
be to write a SUID daemon that, when prodded, will dump this information
into shared memory.  Thus, the program itself need not be running in a
privileged state.

However, the point remains, any mucking about such as this is inherently
non-portable.
-- 
Michael Stefanik                       | Opinions stated are not even my own.
Systems Engineer, Briareus Corporation | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
technoignorami (tek'no-ig'no-ram`i) a group of individuals that are constantly
found to be saying things like "Well, it works on my DOS machine ..."



More information about the Comp.unix.programmer mailing list