  printing process states from C? 
 The Question is:
 
My question is about how to use the STARLET macros from C in general and the
 $STATEDEF macro in specific.  When the manual
 (http://www.openvms.compaq.com:8000/72final/4527/4527pro_044.html) states for
 SYS$GETJPI:
...
JPI$_STATE
When you specify JPI$_STATE, $GETJPI returns the state of the process, which is
 a longword integer value. Each state has a symbolic representation. If the
 process is currently executing, its state is always SCH$K_CUR. The $STATEDEF
 macro defines the follo
wing symbols, which identify the various possible states...
 
How do you make use of this information?  I've gotten the value of JPI$_STATE.
 But I don't see how the $STATEDEF macro used.  I want to get the same
 information displayed by SHOW SYSTEM (CUR, LEF...).  C code example greatly
 appreciated.
 
Here's the modified code from that link above.
/*  Defining __NEW_STARLET enables the program to benefit from better type
    checking for prototypes and structures provided by OpenVMS.
*/
 
#define     __NEW_STARLET       1
 
#include    &lt;efndef&gt;            /*  No Event Flag Event Flag  */
#include    &lt;iledef&gt;            /*  Item List Entry Definitions  */
#include    &lt;iosbdef&gt;           /*  I/O Status Block Structure Definition  */
#include    &lt;jpidef&gt;            /*  $GETJPI Item Code Definitions  */
#include    &lt;ssdef&gt;             /*  SS Message Codes  */
#include    &lt;starlet&gt;           /*  Function Prototypes for System Services */
#include    &lt;stdio&gt;             /*  C Standard I/O Functions  */
#include    &lt;string&gt;            /*  MEMSET Prototype  */
#include    &lt;stsdef&gt;            /*  Status Block Definitions  */
 
#define     NUM_ILE               6
#define     NAME_LENGTH          16
#define     IMAGE_LENGTH        255
 
 
/*  Macro to initialize a 32-bit item_list_3.                 */
 
#define init_ile32(ile, length, code, bufaddr, retlen_addr) \
{   (ile)-&gt;ile3$w_length = (length);           \
    (ile)-&gt;ile3$w_code = (code);         \
    (ile)-&gt;ile3$ps_bufaddr = (bufaddr); \
    (ile)-&gt;ile3$ps_retlen_addr = (retlen_addr); }
main ()
 
char
    imagename [IMAGE_LENGTH],
    procname [NAME_LENGTH],
    username [NAME_LENGTH];
 
int
    count = 0,
    retpid,
    status;
 
unsigned int
    pid = -1;
 
unsigned short
    imagename_length,
    procname_length,
    username_length;
 
long
    state;
ILE3
    jpi_ile [NUM_ILE];
 
IOSB
    iosb;
 
 
/*  Zeroing the item list has the effect of creating the terminating entry. */
 
    memset (jpi_ile, 0, ILE3$K_LENGTH*NUM_ILE);
 
 
/*  Initialize the item list entries to fetch the user name, the process
    name, the image name and the PID.                                     */
 
    init_ile32 (
        &amp;jpi_ile [0],
        NAME_LENGTH,
        JPI$_USERNAME,
        username,
        &amp;username_length);
 
    init_ile32 (
        &amp;jpi_ile [1],
        NAME_LENGTH,
        JPI$_PRCNAM,
        procname,
        &amp;procname_length);
 
    init_ile32 (
        &amp;jpi_ile [2],
        IMAGE_LENGTH,
        JPI$_IMAGNAME,
        imagename,
        &amp;imagename_length);
 
    init_ile32 (
        &amp;jpi_ile [3],
        sizeof (int),
        JPI$_PID,
        &amp;retpid,
        NULL);
 
    init_ile32 (
        &amp;jpi_ile [4],
        sizeof (long),
        JPI$_STATE,
        &amp;state,
        NULL);
 
 
/*  Initial wildcard $GETJPI.
*/
 
    status = sys$getjpiw (
        0,
        &amp;pid,
        NULL,
        &amp;jpi_ile,
        &amp;iosb,
        NULL,
        0);
/*  Loop for all processes on this node.                        */
 
    while (status != SS$_NOMOREPROC)
    {
        if (status &amp; STS$M_SUCCESS)
        {
 
 
/*  Zero terminate process and image name strings.               */
 
            imagename [imagename_length] = '\0';
            username [username_length] = '\0';
            procname [procname_length] = '\0';
 
 
/*  Print header if this is the first.                           */
 
            if (count == 0)
                printf ("   PID   User Name       State  Process Name Image\n");
 
 
 
/*  Count process and print process data.                          */
 
            count++;
            printf ("%08X %-15s %-15s %2ld %s\n",
                retpid,
                username,
                procname,
                state, /* really want CUR,LEF... */
                imagename);
        }
 
 
/*  Skip process if suspended or no privilege to see process.  Return any
    other error.                                                         */
 
        else if ((status != SS$_NOPRIV) &amp;&amp; (status != SS$_SUSPENDED))
            return (status);
 
 
/*  Find next process.                                                    */
 
        status = sys$getjpiw (
            0,
            &amp;pid,
            NULL,
            &amp;jpi_ile,
            &amp;iosb,
            NULL,
            0);
    }
    return (SS$_NORMAL);
 
 
 
Thanks
 
 The Answer is:
The values in $STATEDEF give you a symbolic representation of the numeric
state value. They do not provide strings or any other ASCII representation of
the process state.
 
The symbols can be used in a program like so:
 
    status = sys$getjpiw (
        0,
        &amp;pid,
        NULL,
        &amp;jpi_ile,
        &amp;iosb,
        NULL,
        0);
 
    if (state == SCH$C_CUR)
    {
       ...do something...
    }
 
If you want to print something out, you have to do something like this in
your program:
 
char *state_names[SCH$C_CUR] = {
     "unused\0",
     "COLPG\0",
     "MWAIT\0",
     "CEF\0",
     "PFW\0",
    ...etc...
     }
 
And then, in your printf statement:
 
            printf ("%08X %-15s %-15s %2ld %s\n",
                retpid,
                username,
                procname,
                state_names[state],   /* *****
                imagename);
 
This is how it's done inside the code that processes the SHOW SYSTEM command.
 
 
Also, just to be pendantic, $STATEDEF is in LIB, not STARLET...
 
 
