HP OpenVMS Systems

ask the wizard
Content starts here

Process management programming techniques?

» close window

The Question is:

What is the traditional (correct) way of determining whether a process is still
 alive (exists) at C level?
I know I could do a sys$getjpi() to get it, but I have to ask some specific
 info about the process to call getjpi(). 1. Is there JPI$_<something> that
 tells me only whether it is alive and nothing else (extra info is all right,
 except that no extra info m
ight make it faster)? 2. If no such flag exists, which flag is the fastest?
Thanks a lot,

The Answer is :

  If you insist on using a polling-based scheme -- an approach that the
  OpenVMS Wizard would not recommend, then there are several techniques
  that are available.  Most commonly...
  If the targetted process can handle spurious wakes, then the cheapest
  method might be to call sys$wake for the process identification (PID)
  and check the status.
  Another approach would involve the use of sys$getjpi to ask for nothing
  from the target process, the call will succesfully complete -- not doing
  anything, but successfully -- if the PID exists and the call will fail
  to do nothing if the PID is no longer valid.  Check the return status
  from the sys$getjpi call.
  An example program follows:
#include <efndef.h>
#include <ssdef.h>
#include <starlet.h>
#include <stdio.h>
#include <stsdef.h>
main(int argc, char *argv[])
	int RetStat, Null = 0, Pid;
        unsigned short int IOSB;
        sscanf( argv[1], "%x", &Pid );
	RetStat = sys$getjpiw( EFN$C_ENF, &Pid, 0, &Null, IOSB, 0, 0);
	if (!$VMS_STATUS_SUCCESS( RetStat ))
          return RetStat;
          return IOSB;
        return SS$_NORMAL;
  Alternatively, use the process termination mailbox mechanism.
  Polling based on scans for a process name is NOT recommended.
  A technique that would be greatly prefered by the OpenVMS Wizard would
  involve the use of the OpenVMS Distributed Lock Manager.  Have the
  target process queue an exclusive lock on a resource such as FOO_ALIVE
  (where FOO is a prefix unique to this application) or FOO_SCSNODE_ALIVE
  (where the SCSNODE string is replaced with the name of the local node,
  if more than one copy of this monitored process will be running within
  an OpenVMS Cluster), and queue a request (with a granting AST specified)
  with an incompatible lock mode (eg: exclusive) in the monitoring process.
  When (if) the monitored process exits (or if the node itself exits within
  an OpenVMS Cluster), the monitoring process will receive the lock and the
  grant AST will be triggered.
  For details on this, please see the $enq and $deq documentation in
  the OpenVMS documentation set.
  Using the lock manager has the advantage of immediate notification,
  and also avoids the need to track the target PID.

answer written or last revised on ( 7-DEC-2000 )

» close window