Path: utzoo!attcan!uunet!husc6!mailrus!purdue!decwrl!ucbvax!phast.phys.washington.EDU!SEYMOUR
From: SEYMOUR@phast.phys.washington.EDU
Newsgroups: comp.os.vms
Subject: RE: open file count from a program
Message-ID: <8807050117.AA28118@ucbvax.Berkeley.EDU>
Date: 1 Jul 88 21:51:00 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The Internet
Lines: 53

Peter Beckmann in Munster  asked:

>does anyone know a possiblity to get information about the number of
>opened files from within a program.

the answer is:  CALL SYS$GETJPIW asking for two pieces of information.
(system services manual, around page sys-213)

you want jpi$_FILLM   (your process's open file limit) and
        jpi$_FILCNT  (how many remain of that limit)
subtract the second from the first, and you've got how many are open
(including the program's .exe itself, etc. -- thus an overhead of 1)

messy fortran sample: (no structures, just good ol' equivalences)
-------------------------------cut here------------------------------
        implicit integer*4 (a-z)
        integer*2 itemword(18)
        integer*4 itemlist(9)
        equivalence (itemword,itemlist)
        integer*4 filelimit, filesleft, filesopen
        integer*4 lenlimit, lenleft

        include '($jpidef)'

        itemword(1)=4                   ! authorized length of result
        itemword(2)=jpi$_fillm          ! open file limit (from UAF)
        itemlist(2)=%loc(filelimit)     ! where to put the answer
        itemlist(3)=%loc(lenlimit)      ! how many bytes came back

        itemword(7)=4
        itemword(8)=jpi$_filcnt
        itemlist(5)=%loc(filesleft)
        itemlist(6)=%loc(lenleft)

        itemlist(7)=0                   ! end of request list

c we call the WAIT version of the service
c  defaulting everything

        call sys$getjpiw(,,,itemlist,,,)

        filesopen=filelimit-filesleft
        type *,'quota:',filelimit,', remaining:',filesleft
        type *,'there are',filesopen,' files open'
        end
-----------------------cut here-----------------------------------------
(i get "2" when i run it from a command file, "1" from my terminal)
 -- see also the little book "guide to programming on VAX/VMS (Fortran edition)
   page 3-33.

there's also a lexical function (f$getjpi) for DCL usage.

-- dick seymour    seymour@uwaphast   "messy (but tested) code for all to see"