[comp.unix.shell] Who redirects to a file?

ellis@ultra.dec.com (David Ellis 16-Oct-1990 1136) (10/16/90)

Given a specific file, how can the following be done in csh:

(a) Determine whether there exists a process whose output is currently 
redirected into the file.

(b) Same as (a), but the file is NFS-mounted with its original on another 
machine.

(c) As in (b), but you want to test for processes on other machines that
may be redirecting their output to your file via a NFS pointer on their
machine.

----
David  J  Ellis
Digital Equipment Corporation, Secure Systems Group 
Mailstop BXB1-1/D03 
85 Swanson Road, Boxboro MA 01719 
(508) 264-5073 
Usenet:   {ucbvax,allegra,decvax}!decwrl!ultra.enet!ellis
Internet: ellis@ultra.enet.dec.com

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (10/16/90)

In article <9010161533.AA19292@decpa.pa.dec.com> ellis@ultra.dec.com (David Ellis 16-Oct-1990 1136) writes:
> (a) Determine whether there exists a process whose output is currently 
> redirected into the file.

Remove the file and see whether any disk space clears up.

Seriously, there's no good way to get the soft link count. You could try
``ofiles'' on machines where it works, but it isn't reliable.

If there were an enforce() call to enforce the new permissions on a
file, I don't know why you'd care who had the file open. After all, if
the permissions are still open, anyone could sneak in and out of the
file at any time, so your test wouldn't be reliable. And if they aren't,
why are you checking access if you don't want to cut it off?

---Dan

mills@ccu.umanitoba.ca (Gary Mills) (10/17/90)

ellis@ultra.dec.com (David Ellis 16-Oct-1990 1136) writes:

>Given a specific file, how can the following be done in csh:

>(a) Determine whether there exists a process whose output is currently 
>redirected into the file.
[...]
>(c) As in (b), but you want to test for processes on other machines that
>may be redirecting their output to your file via a NFS pointer on their
>machine.

In this situation, about all you can do is lock the file, with something
like lockf(3).  It even works across NFS mounts in SunOS 4.1.1, 
for example.
-- 
-Gary Mills-             -University of Manitoba-             -Winnipeg-