[comp.os.vms] LIB$GETJPI

sysmgr@JALCF.WPAFB.AF.MIL ("SYSTEM") (07/05/88)

Fortraners,

	I want to use LIB$GETJPI to return information on any process
running on the system. The ORANGE book gives me this:

LIB$GETJPI  item-code,[,process-id] [,process-name] [,outvalue]....etc

	The problem I'm having is with the [,process-id] part. The book
tells us the process-id is "the address of an unsigned longword containing 
the process identification." How do I fill this parameter?

	If I want LIB$GETJPI to return certain information on process 23d
how would I put it in [,process-id]????

	Any help on this subject would be greatly appreciated!

Thanx

Don

------

cfchiesa@bsu-cs.UUCP (Christopher Chiesa) (07/07/88)

In article <8807071431.AA22249@ucbvax.Berkeley.EDU>, sysmgr@JALCF.WPAFB.AF.MIL ("SYSTEM") writes:
> 
> 	I want to use LIB$GETJPI to return information on any process
> running on the system. The ORANGE book gives me this:
> 
> LIB$GETJPI  item-code,[,process-id] [,process-name] [,outvalue]....etc
> 
> 	The problem I'm having is with the [,process-id] part. The book
> tells us the process-id is "the address of an unsigned longword containing 
> the process identification." How do I fill this parameter?
> 

I know the feeling.  I used to get all tangled up in the "address of an
unsigned longword..." syntax of the Orange Books, too.  

What this means, is that rather than passing LIB$GETJPI the actual value
of the process-id you want to look at, you pass the ADDRESS of the place
where the actual value is stored.  If you've ever programmed in Pascal,
for example, this is the difference between "non-VAR" and "VAR" parame- 
ters to a procedure or function.  In VMS it is designated as "by value"
vs. "by reference."

It's been a while since I programmed in FORTRAN, but I believe you can
take care of the problem something like so:

       INTEGER*4 PID         <---  "*4" makes it a LONGWORD
          .
          .
          .
       [whatever you have to do to put a value in PID, and
        invoke LIB$GETJPI...]

         STATUSCODE = LIB$GETJPI( item_code, %LOC PID, .... )

The %LOC modifier forces the compiler to code for passing of PID "by 
reference," rather than "by value" which is apparently the default.
Like I said, it's been a while; if any more up-to-date FORTRANers 
would care to correct me, that's fine!

> 	If I want LIB$GETJPI to return certain information on process 23d
> how would I put it in [,process-id]????

Well, in my experience, you have to use the FULL 8-hex-digit (32-bit,
i.e. a LONGWORD) process-id, rather than just the last few digits which
are unique from one process to the next.   Also you must beware that 
the PID must be represented in binary, NOT as an eight-character read-
able STRING...  Note that PIDs are generally displayed in HEX by VMS,
so you'd need to perform some sort of input conversion if you wanted to
be able to TYPE IN a hex PID value and send it to LIB$GETJPI.  In MACRO,
I use LIB$GET_INPUT to obtain the string representation of PID, then 
use LIB$CVT_XTB to turn that into the binary representation needed for 
LIB$GETJPI.  

> 
> 	Any help on this subject would be greatly appreciated!
> 
> Thanx
> 
> Don
 
I hope this HAS helped somewhat...

   Chris

-- 
UUCP: <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!cfchiesa 
cfchiesa@bsu-cs.UUCP                                           

carl@CITHEX.CALTECH.EDU (Carl J Lydick) (07/08/88)

 > 	I want to use LIB$GETJPI to return information on any process
 > running on the system. The ORANGE book gives me this:
 > 
 > LIB$GETJPI  item-code,[,process-id] [,process-name] [,outvalue]....etc
 > 
 > 	The problem I'm having is with the [,process-id] part. The book
 > tells us the process-id is "the address of an unsigned longword containing 
 > the process identification." How do I fill this parameter?
 > 
 > 	If I want LIB$GETJPI to return certain information on process 23d
 > how would I put it in [,process-id]????
 > 
 > 	Any help on this subject would be greatly appreciated!

The following program illustrates the use of LIB$GETJPI:
C*******************************************************************************
	CHARACTER*16 NAME
	JPI$_PRCNAM='031C'X
	TYPE 10
10	FORMAT(' PID: ',$)
	ACCEPT 20, IPID
20	FORMAT(Z8)
	CALL LIB$GETJPI(JPI$_PRCNAM,IPID,,,NAME,NAMLEN)
	TYPE *, NAME(1:NAMLEN)
	END
C*******************************************************************************
Technically, I should have declared IPID as LOGICAL*4 to make it an unsigned
longword, but in this context, it doesn't make any difference.

ijah400%ivax.DECnet@GOLD.BACS.INDIANA.EDU ("IVAX::IJAH400") (07/14/88)

Christopher Chiesa <bsu-cs!cfchiesa@IUVAX.CS.INDIANA.EDU> writes (about
passing arguments by reference to library routines):
< In article <8807071431.AA22249@ucbvax.Berkeley.EDU>, sysmgr@JALCF.WPAFB.AF.MIL
< ("SYSTEM") writes:
< ...
<        [whatever you have to do to put a value in PID, and
<         invoke LIB$GETJPI...]
<
<          STATUSCODE = LIB$GETJPI( item_code, %LOC PID, .... )
<
< The %LOC modifier forces the compiler to code for passing of PID "by
< reference," rather than "by value" which is apparently the default.
< Like I said, it's been a while; if any more up-to-date FORTRANers
< would care to correct me, that's fine!

OK, here goes:  %LOC is an built-in function that gives the address of its
argument as the result.  But
         STATUSCODE = LIB$GETJPI( item_code, %LOC PID, .... )
gives a syntax error, because %LOC(PID) is legal but %LOC PID is not.
Furthermore, that isn't what the guy wants, because %LOC(PID) ends up passing
the ADDRESS of PID by reference (i.e., the address of a longword containing
the address of PID).  What he wants is:
         STATUSCODE = LIB$GETJPI( item_code, %REF(PID), .... )
or       STATUSCODE = LIB$GETJPI( item_code, PID, .... )
which generate the same code, as the default argument passing mechanism in
VAX FORTRAN is by REFERENCE.  The built-in function %REF may be used in
actual argument lists to be picky about the fact that you want something
passed by reference.  VAX FORTRAN also has an built-in function %VAL to
specify that an argument be passed by value, %DESCR to pass the address of
a descriptor (the default for CHARACTER data, etc., RTFM).

Note that the FORTRAN-77 standard does not REQUIRE that arguments be passed
by reference; the value-result (copy-in, copy-out) mechanism is OK too.
For example, the PDP-10 (TOPS-10 and TOPS-20) FORTRAN compilers use the
value-result mechanism for scalar data items.  It really only makes a
difference if your programmers are doing things prohibited by the FORTRAN
standard (like passing a COMMON variable to a routine that refers to it both
by the COMMON variable name and the formal argument name).  All the other
FORTRAN compilers I've ever encountered, including VAX FORTRAN, use the
reference mechanism by default.

Hope this helps....

        James Harvey
        ijah400@indyvax (bitnet) or ijah400%ivax.decnet@gold.bacs.indiana.edu