Zeroshade
Zeroshade

Reputation: 573

Sending signals from DCL command line on OpenVMS

I'm trying to send a signal via the command line on an OpenVMS server. Using Perl I have set up signal handlers between processes and Perl on VMS is able to send Posix signals. In addition, C++ programs are able to send and handle signals too. However, the problem I run into is that the processes could be running on another node in the cluster and I need to write a utility script to remotely send a signal to them.

I'm trying to avoid writing a new script and would rather simply execute a command remotely to send the signal from the command line. I need to send SIGUSR1, which translates to C$_SIGUSR1 for OpenVMS.

Thanks.

Upvotes: 0

Views: 447

Answers (1)

Jim
Jim

Reputation: 83

As far as I know, there is no supported command line interface to do this. But you can accomplish the task by calling an undocumented system service called SYS$SIGPRC(). This system service can deliver any condition value to the target process, not just POSIX signals. Here's the interface described in standard format:

FORMAT

     SYS$SIGPRC process-id ,[process-name] ,condition-code

RETURNS

     OpenVMS usage: cond_value
     type:          longword (unsigned)
     access:        write only
     mechanism:     by value

ARGUMENTS

     process-id

     OpenVMS usage: process_id
     type:  longword (unsigned)
     access:    modify
     mechanism:     by reference

     Process identifier of the process for which is to receive the signal. The
     process-id argument is the address of an unsigned longword containing the
     process identifier. If you do not specify process-id, process-name is
     used.

     The process-id is updated to contain the process identifier actually
     used, which may be different from what you originally requested if you
     specified process-name.

     process-name

     OpenVMS usage: process_name
     type:          character string
     access:        read only
     mechanism:     by descriptor

     A 1 to 15 character string specifying the name of the process for
     which will receive the signal. The process-name argument is the
     address of a descriptor pointing to the process name string. The name
     must correspond exactly to the name of the process that is to receive
     the signal; SYS$SIGPRC does not allow trailing blanks or abbreviations.

     If you do not specify process-name, process-id is used. If you specify
     neither process-name nor process-id, the caller's process is used.
     Also, if you do not specify process-name and you specify zero for
     process-id, the caller's process is used.

     condition-value

     OpenVMS usage: cond_value
     type:          longword (unsigned)
     access:        read only
     mechanism:     by value

     OpenVMS 32-bit condition value. The condition-value argument is
     an unsigned longword that contains the condition value delivered
     to the process as a signal.

     CONDITION VALUES RETURNED

     SS$_NORMAL    The service completed successfully
     SS$_NONEXPR   Specified process does not exist
     SS$_NOPRIV    The process does not have the privilege to signal
                   the specified process
     SS$_IVLOGNAM  The process name string has a length of 0 or has
                   more than 15 characters
     (plus I suspect there are other possible returns having to do
      with various cluster communications issues)

EXAMPLE CODE

#include <stdio.h>
#include <stdlib.h>
#include <ssdef.h>
#include <stsdef.h>
#include <descrip.h>
#include <errnodef.h>
#include <lib$routines.h>

int main (int argc, char *argv[]) {
/*
**
** To build:
**
**      $ cc sigusr1
**      $ link sigusr1
**
** Run example:
**
**      $ sigusr1 := $dev:[dir]sigusr1.exe
**      $ sigusr1 20206E53
**
*/

static unsigned int pid;
static unsigned int r0_status;
extern unsigned int sys$sigprc (unsigned int *,
                                struct dsc$descriptor_s *,
                                int);

    if (argc < 2) {
        (void)fprintf (stderr, "Usage: %s PID\n",
                       argv[0]);
        exit (EXIT_SUCCESS);
    }

    sscanf (argv[1], "%x", &pid);

    r0_status = sys$sigprc (&pid, 0, C$_SIGUSR1);
    if (!$VMS_STATUS_SUCCESS (r0_status)) {
        (void)lib$signal (r0_status);
    }
}

Upvotes: 1

Related Questions