mike@mipos3.UUCP (Michael Bruck) (08/12/86)
How can one tell which users have what files open? I essentially need to see if a particular file is open and by whom. On VMS (no flames please), a SHOW DEVICES/FILES does this. Other than writing a program that crawls around the insides of the i-node tables and file buffer tables, I can't come up with any way of doing this. Any ideas? --Michael Bruck Intel CAD, Santa Clara, CA ...{decwrl,amdcad,hplabs}!intelca!mipos3!mike
hope@gatech.CSNET (Theodore Hope) (08/14/86)
In article <157@mipos3.UUCP> mike@mipos3.UUCP (Michael Bruck) writes: >How can one tell which users have what files open? I essentially need >to see if a particular file is open and by whom. The 'fuser' program on System V does this kind of thing. It's SLOW, but better than nothing. It crawls around the inode tables, etc, and that's what you'll have to do if you want to write one yourself. -- Theodore Hope School of Information & Computer Science, Georgia Tech, Atlanta GA 30332 CSNet: hope@gatech ARPA: Hope%GATech.CSNet @ CSNet-Relay.ARPA uucp: ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-sally}!gatech!hope
mike@mipos3.UUCP (Michael Bruck) (08/16/86)
I earlier asked: > How can one tell which users have what files open? I essentially need > to see if a particular file is open and by whom. Thanks to everyone on the net who responded. As I found out, on system V, there's a program called fuser which does what I want. Unfortunately, I'm using Ultrix (a.k.a. BSD 4.2~3) so following a suggestion by someone about using pstat -i to get the UID's of all the files open, I came up with the following quick and dirty shell that does the job. It's kind of slow and cumbersome but it saved me from writing a new program and it works well enough for my needs. It's short enough not to bother with net.sources. ------------------------------------------------------------------------- #!/bin/csh set noglob set com = $0 if ($#argv == 0) then echo2 "Usage: $com:t file" exit 1 endif foreach ifile ($argv[*]) if ( ! -f $ifile ) then echo $ifile not found exit 1 endif set inode=`ls -i $ifile` set user=`pstat -i | grep $inode[1] | awk -F, '{print $2}'` if ( "$user" != "" ) then set name=`grep $user[7] /etc/passwd | awk -F: '{print $1}'` echo $name has $ifile open else echo $ifile not open endif end ------------------------------------------------------------------------- --Michael Bruck Intel CAD, Santa Clara, CA {decwrl,hplabs,amdcad}!intelca!mipos3!mike