From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 12-JUN-1989 15:34
To:	MRGATE::"ARISIA::EVERHART"
Subj:	VMS 5.2, SYS$PROCESS_SCAN example code of things (maybe?) to be

Message-Id:  <8906121645.AA01657@crdgw1.ge.com>
Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Mon, 12 JUN 89 07:36:48 PDT
Received: from CUNYVM.CUNY.EDU by KL.SRI.COM with TCP; Sun, 11 Jun 89 14:35:27 PDT
Received: from FHCRCVAX.BITNET by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with BSMTP id 8438; Sun, 11 Jun 89 17:35:36 EDT
Date: Sun, 11 Jun 89 14:36 PST
From: Joe Meadows <JOE%FHCRCVAX.BITNET@CUNYVM.CUNY.EDU>
Subject: VMS 5.2, SYS$PROCESS_SCAN example code of things (maybe?) to be
To: info-vax@kl.sri.com
X-Vms-To: INFO-VAX

(how weird, I posted this several days ago, but it appears to
have bounced back to me, so here it is (again?).

Hello all,

I was lucky enough to recently have access to a V5.2 machine, and in browsing
around, I found sh*tloads of new routines. Most looked like they were probably
to support RDB, so I ignored them :) but two interesting ones popped up
and I decided to figure them out. Of course, if these are in V5.2 for real
then they are probably documented as well, but I haven't seen that myself.

The two routines SYS$PROCESS_SCAN and SYS$DEVICE_SCAN allow you to more
easily access processes and devices respectively. This example program
demonstrates the use of SYS$PROCESS_SCAN to do the infamous, search processes
by process-name. No longer will you be stuck getting only processes in your
UIC group. SYS$PROCESS_SCAN does a whole lot more than this actually, in
conjunction with a highly modified SYS$GETJPI it can now return information
for any process on any node in a cluster.. It's real spiffy, and I understand
that CW Hobbs gave a talk on it at the Atlanta DECUS. If anyone has notes
on this talk (about the cluster wide process services), I would appreciate a
copy!

Anyway, here's some code, can't say if anybody out there actually has a use
for it since V5.2 isn't real yet (is it?) It should give you something to
look forward to I suppose!

Cheers,
Joe Meadows     joe@fhcrcvax.bitnet

$ create/log PSCAN.C
$DECK
#include <jpidef.h>
#include "$pscandef.h"  /* new with VMS 5.2 */

/* This is an example program, to use it, compile it, link it, and define
   a foreign command, such as PSCAN == "$device:[directory]PSCAN"
   You may then pass it (space separated) process names to look for, as in:
        $ PSCAN prcnam1 prcnam2
   The process_scan item-list is somewhat different from a regular item
   list, in that nothing can be returned from that call, so the return-length
   address field has been modified as a flags field. With this field you
   can specify such niceties as whether to do a case-blind and/or wildcard
   search (among other things), as is done in this example.
*/

main(int argc, char *argv[])
{
  int pid;
  char username[13];
  short userlen;
  struct ItmLst
  {
    short length;
    short code;
    long bufadr;
    long retlenadr;
  } jpilst[] =
    { {4, JPI$_PID,&pid,0},
      {12,JPI$_USERNAME,username,&userlen},
      {0,0,0,0}
    },
    pscanlst[] =
    { {0,PSCAN$_PRCNAM,0,PSCAN$M_CASE_BLIND | PSCAN$M_WILDCARD},
      {0,0,0,0}
    };
  int pidctx = 0;
  int sts, i;

  for (i = 1; i < argc; ++i)
  {
    pscanlst[0].length = strlen(argv[i]);
    pscanlst[0].bufadr = argv[i];

    sts = sys$process_scan(&pidctx,pscanlst);
    if (!(sts & 1))
      lib$signal(sts);

    while(sts & 1)
    {
      sts = sys$getjpiw(0,&pidctx,0,jpilst,0,0,0);
      if (sts & 1)
        printf("%08X %.*s\n",pid,userlen,username);
    }
  }
}
$EOD
$ create/log $PSCANDEF.H
$DECK
/* Created by SDL V3.1-7     */
/* Source: 12-MAY-1989 13:45:04 MASS$DISK:[JOE.VMS5]STARDEFMP.SDI;1 */
#ifndef $PSCANDEF_H
#define $PSCANDEF_H

/*** MODULE $PSCANDEF ***/
/*+                                                                          */
/*                                                                           */
/* Process_Scan item code definitions                                        */
/*                                                                           */
/*-                                                                          */
/* Item code definitions                                                     */
#define PSCAN$_BEGIN 0
#define PSCAN$_ACCOUNT 1        /* Match on account name                     */
#define PSCAN$_AUTHPRI 2        /* Match on authorized priority              */
#define PSCAN$_CURPRIV 3        /* Match on current privs                    */
#define PSCAN$_GRP 4    /* Match on GRP field                                */
#define PSCAN$_HW_MODEL 5       /* Match on system's HW_MODEL                */
#define PSCAN$_HW_NAME 6        /* Match on system's HW_NAME                 */
#define PSCAN$_JOBPRCCNT 7      /* Match on job subprocess count             */
#define PSCAN$_JOBTYPE 8        /* Match on job origin type field            */
#define PSCAN$_MASTER_PID 9     /* Match on PID of master process            */
#define PSCAN$_MEM 10   /* Match on MEM field                                */
#define PSCAN$_MODE 11  /* Match on process mode                             */
#define PSCAN$_NODE_CSID 12     /* Match on system's CSID                    */
#define PSCAN$_NODENAME 13      /* Match on system's nodename                */
#define PSCAN$_OWNER 14 /* Match on PID of owner                             */
#define PSCAN$_PRCCNT 15        /* Match on subprocess count                 */
#define PSCAN$_PRCNAM 16        /* Match on process name                     */
#define PSCAN$_PRI 17   /* Match on current priority                         */
#define PSCAN$_PRIB 18  /* Match on base priority                            */
#define PSCAN$_STATE 19 /* Match on process state                            */
#define PSCAN$_STS 20   /* Match on process status                           */
#define PSCAN$_TERMINAL 21      /* Match on terminal name                    */
#define PSCAN$_UIC 22   /* Match on UIC field                                */
#define PSCAN$_USERNAME 23      /* Match on username                         */
#define PSCAN$_GETJPI_BUFFER_SIZE 24    /* Buffer for blocking               */
#define PSCAN$_END 25
#define PSCAN$K_TYPE 129
#define PSCAN$M_OR 0x00000001
#define PSCAN$M_BIT_ALL 0x00000002
#define PSCAN$M_BIT_ANY 0x00000004
#define PSCAN$M_GEQ 0x00000008
#define PSCAN$M_GTR 0x00000010
#define PSCAN$M_LEQ 0x00000020
#define PSCAN$M_LSS 0x00000040
#define PSCAN$M_PREFIX_MATCH 0x00000080
#define PSCAN$M_WILDCARD 0x00000100
#define PSCAN$M_CASE_BLIND 0x00000200
#define PSCAN$M_EQL 0x00000400
#define PSCAN$M_NEQ 0x00000800
struct item_specific_flags {
    unsigned pscan$v_or : 1;    /* Logical OR of items                       */
    unsigned pscan$v_bit_all : 1;       /* All bits set in pattern           */
    unsigned pscan$v_bit_any : 1;       /* Any bit set in pattern            */
    unsigned pscan$v_geq : 1;
    unsigned pscan$v_gtr : 1;
    unsigned pscan$v_leq : 1;
    unsigned pscan$v_lss : 1;
    unsigned pscan$v_prefix_match : 1;  /* Match on leading substring        */
    unsigned pscan$v_wildcard : 1;      /* Wildcard pattern                  */
    unsigned pscan$v_case_blind : 1;    /* Ignore case of text strings       */
    unsigned pscan$v_eql : 1;
    unsigned pscan$v_neq : 1;
    unsigned pscan$v_fill_63 : 4;
} ;
#endif
$EOD


