Operating System - OpenVMS
1753830 Members
8581 Online
108806 Solutions
New Discussion юеВ

Get open files and username

 
SOLVED
Go to solution
Dario Karlen
Frequent Advisor

Get open files and username

Hi all,
i have to write some fortran 90 programs. i want to check if a file is already open and which user has it open. in fortran i have no idea how to handle it. is there a possibility in vms to check if the specified file is open and to get the user? i can see the open files with show device dsa2:/files, but i need the information in a program. any idea? thanks for your help!
8 REPLIES 8
Uwe Zessin
Honored Contributor
Solution

Re: Get open files and username

That information is hidden deep in the operating system and, in case of a VMScluster, can be even on a remote node.

If the environment is under your control, how about using the lock manager to communicate across nodes - the lock value block can easily hold a PID and SYS$GETJPI[W]() work cluster-wide for many item codes.
.
Kris Clippeleyr
Honored Contributor

Re: Get open files and username

Dario,
Have a look at the FILES_INFO package at
http://vms.process.com/scripts/fileserv/fileserv.com?FILES_INFO
It's pretty old (1992) and written in C and Macro, but maybe it gives you a few ideas on how to do this in Fortran.
Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Hein van den Heuvel
Honored Contributor

Re: Get open files and username


To find out whether a file is open is trivial. Just try opening it exclusively (NOT shared) and if that fails with a sharing violation then it must have been open!

Now to find out who, in the cluster, has it open is much, much, more difficult. The easiest route is probably a GETLKI hunting for the lock corresponding with the file and listing the PID... on each node.

If it is part of your application, then you may be better of defining your open file open registration method. For example, you could define your own 'file lock' with the last accessor pid, node and maybe username in the (16 bytes only) lock value block.

hth,
Hein.
Paul Jerrom
Valued Contributor

Re: Get open files and username

You can do it easily enough from DCL (Hey, you can do ANYTHING from DCL!).

Do a show device/file/nosys to an output file on each cluster member (via sysman), then search the output files for the file.
Will give every process that has a current channel to the file, irrespective of whether the process has taken a lock or not.
Have fun,

Peejay
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If it can't be done with a VT220, who needs it?
Dario Karlen
Frequent Advisor

Re: Get open files and username

ok, but how can i search a string in a file in a fortran program.
with a dcl command no problem: search file.txt string, but how to do this in a fortran program???
Uwe Zessin
Honored Contributor

Re: Get open files and username

You need to open the file, read it record by record and look for the string in the buffer. You might want to play with the string manipulation library (e.g. STR$UPCASE), because the DCL SEARCH by default does a case insensitive lookup.
.
Joseph Huber_1
Honored Contributor

Re: Get open files and username

How to search for a string ?
Open the file
Loop reading record by record until EOF
is the search string in this record ?
if yes , go process , else continue loop.

The VMS run-time library offers a routine
STR$FIND_FIRST_SUBSTRING
see HELP RTL STR$ .
Use the file-name as the search string. If it matches, take the processname or processID from the beginning of the matched record to identify the process.
http://www.mpp.mpg.de/~huber
Dario Karlen
Frequent Advisor

Re: Get open files and username

thanks, that's excatly what i need!!