From:	HENRY::IN%"xrjjm%scint.span%jpl-vlsi.arpa%kl.sri.com%csnet-relay.CSNET%relay.cs.net@RCA.COM"  4-JUN-1987 19:14
To:	Info-Vax@kl.sri.com
Subj:	You are logged in 27 times !


Well, if you are worried about how many times a user is logged in, one of the
best ways to check it is by calling the F$PID routine and seeing how many 
PID's are active for your account.  If more than one is active, then you
must have more than one session logged in (or a subprocess, or a batch job...
etc.)

Below is a program (written in DCL) which will list all of your current 
processes, what they are doing, and what terminal they are logged into.
The program requires no privileges, and VMS 4.4.  I threw in a Help file,
and the CHECKSUM numbers, just in case your mailer chews on source code.

As usual, this program is distributed "AS IS", and I hope you find it of
use.

John J. McMahon - Fast Eddie
XRJJM%CSDR.SPAN@VLSI.JPL.NASA.GOV
(FEDUP Software - Fast Eddie's Digital Utility Programs)

PS: If you don't have VMS 4.4, all you have to do is take the GOSUB's out of the
program and replace them with a GOTO construct.

------------CUT HERE---------------PID_CHECK.COM-------------------------------
$! PID_CHECK.COM - Check to see if a user is logged in multiple times.
$! Requires VMS 4.4 (Uses VMS GOSUB) and No Privileges (GROUP or WORLD will
$! make it act wierd).
$!
$! John J. McMahon, F.E.D.U.P. Software
$! XRJJM%CSDR.SPAN@VLSI.JPL.NASA.GOV
$!
$ Write Sys$output "Executing PID_CHECK.COM"
$ curpriv = F$GETJPI("","CURPRIV")
$ SET PROCESS/PRIV=(NOGROUP,NOWORLD)
$ Context = ""
$ Count = 0
$ Loop:
$ Xyzzy = F$PID(Context)
$ If Xyzzy .nes. "" then Count = Count + 1
$ If Xyzzy .nes. "" then Goto Loop
$ Write Sys$Output "You Are Currently Logged Into ",Count," Sessions."
$ If Count .Ne. 1 then gosub uhoh
$ set process/priv=('curpriv')
$ Exit
$ uhoh:
$ Write Sys$output "WARNING: Multiple Sessions!"
$ curpid = F$GETJPI("","PID")
$ loop:
$ xyzzy = f$pid(context)
$ if xyzzy .eqs. curpid then write sys$output -
     xyzzy," ",F$GetJpi(xyzzy,"PRCNAM")
$ if xyzzy .eqs. curpid then write sys$output "  Current Process"
$ if xyzzy .nes. curpid then gosub noncurpid
$ if xyzzy .nes. "" then goto loop
$ exit
$ noncurpid:
$ comment = ""
$ if xyzzy .eqs. "" then return
$ imagename = F$Getjpi(xyzzy,"IMAGNAME")
$ imagename = F$PARSE(imagename,,,"NAME")
$ if imagename .eqs. "" then imagename = "$ DCL"
$ terminal = F$GetJpi(xyzzy,"TERMINAL")
$ if terminal .eqs. "" then terminal = "None"
$ Mode = F$GetJpi(xyzzy,"MODE")
$ If xyzzy .nes. F$GetJpi(xyzzy,"MASTER_PID") then gosub subproc
$ write sys$output xyzzy," ",F$getjpi(xyzzy,"PRCNAM")
$ write sys$output "  Image: ",imagename," Term: ",-
  TERMINAL," State: ",F$GetJpi(xyzzy,"STATE"),-
  " Mode: ", MODE," ",COMMENT
$ return
$ subproc:
$ XPID1 = F$GetJpi(xyzzy,"MASTER_PID") 
$ Mode = "SUBPROC/"+F$EXTRACT(0,5,F$GETJPI(XPID1,"MODE"))
$ If XPID1 .eqs. curpid then comment = "(*)"
$ If XPID1 .nes. curpid then comment = "("+F$GETJPI(XPID1,"PRCNAM")+")"
$ return
--------------------End Of File-------------Cut Here-----------------------
Note: PID_CHECK.COM has a Checksum Value Of 607410262 under VMS 4.4

----------------Cut Here----------------PID_CHECK.HLP----------------------
1 PID_CHECK

PID_CHECK (Short for Process IDentification number CHECK) is a command 
procedure designed to determine how many times you are logged on a 
given CPU, and what the other processes are doing.  PID_CHECK will count 
the number of active processes, and issue a warning if more than one 
process is active.  It will also detail what the other processes are
currently doing.

To Execute PID_CHECK:

   $ @$1$22:[XRJJM.COMMAND]PID_CHECK

2 Output_Format

If yours is the only process logged on a node, PID_CHECK will report:

"You Are Currently Logged Into 1 Sessions."

If you have two or more processes on a node, PID_CHECK will follow the
"You Are..." message with details on each process.  The details are in
the following format:

For the current process:

    NNNNNNNN PRCNAM                   
      Current Process






For other processes:

    NNNNNNNN PRCNAM
      Image: IMAGNAME Term: TERMINAL State: STAT Mode: MDE EXTRA

NNNNNNNN refers to the Process ID number, which is unique for each process.
PRCNAM is the Process Name.
IMAGNAME is the image currently running.  If the user has a DCL prompt, 
                or is running a command procedure, IMAGNAME = "$ DCL".
TERMINAL is the Terminal Name.
STAT is the current process state (COM = Compute, LEF = Local Event Flag 
                                  Wait, HIB = Hibernate, etc.)
MDE is the type of Login (NETWORK, INTERACTIVE, BATCH, OTHER), Subprocess 
                         Logins will be of the form SUBPROC/MDE, where MDE
                         is the mode of the master process.
EXTRA contains the Process Name of the master of a subprocess, if it's your 
                         process the name will be (*).

2 Examples

Sample Output from a user who has 6 active processes on one node.

Executing Login$:PID_CHECK.COM
You Are Currently Logged Into 6 Sessions.
WARNING: Multiple Sessions!
24E002AD Fast-Eddie~AD
  Current Process
24E003B1 Batch-Eddie~B1
  Image: MMS Term: None State: LEF Mode: BATCH 
24E003B2 XRJJM_1
  Image: DBDEF Term: None State: COM Mode: SUBPROC/BATCH (Batch-Eddie~B1)
24E003B6 NET_6194
  Image: $ DCL Term: None State: LEF Mode: NETWORK 
24E003B7 XRJJM_2
  Image: $ DCL Term: None State: LEF Mode: SUBPROC/INTER (*)
24E003B8 XRJJM
  Image: $ DCL Term: LTA49: State: LEF Mode: INTERACTIVE 

Sample Output from a user who has only 1 process on the node.

Executing Login$:PID_CHECK.COM
You Are Currently Logged Into 1 Sessions.
------------End Of File---------------------Cut Here-------------------------
Note: PID_CHECK.HLP has a CHECKSUM of 2081195890 under VMS 4.4

End Of Mail.
