HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

OpenVMS Alpha Signal-Handling Notes (ALPHA ONLY)

  • While all signals that exist on OpenVMS VAX systems also exist on OpenVMS Alpha systems, the corresponding OpenVMS exceptions and code is different in a number of cases because on Alpha processors there are two new OpenVMS exceptions and several others that are obsolete.
  • All floating-point exceptions on OpenVMS Alpha systems are signaled by the OpenVMS exception SS$_HPARITH (high-performance arithmetic trap). The particular type of trap that occurred is translated by the HP C RTL through use of the exception summary longword, which is set when a high-performance arithmetic trap is signaled.

Table 4-6 HP C RTL Signals and Corresponding OpenVMS I64 Exceptions (I64 ONLY)
Name OpenVMS Exception Generated By Code
SIGABRT SS$_OPCCUS The abort function --
SIGALRM SS$_ASTFLT The alarm function --
SIGBUS SS$_ACCVIO Access violation --
SIGBUS SS$_CMODUSER Change mode user --
SIGCHLD C$_SIGCHLD Child process stopped --
SIGEMT SS$_COMPAT Compatibility mode trap --
SIGFPE SS$_DECOVF Decimal overflow trap FPE_DECOVF_TRAP
SIGFPE SS$_DECDIV Decimal divide trap FPE_DECDIV_TRAP
SIGFPE SS$_DECINV Decimal invalid operand trap FPE_DECINV_TRAP
SIGFPE SS$_FLTDENORMAL Denormal operand fault FPE_FLTDENORMAL_FAULT
SIGFPE SS$_FLTDIV Floating/decimal division by 0 FPE_FLTDIV_TRAP
SIGFPE SS$_FLTDIV_F Floating divide by 0 fault FPE_FLTDIV_FAULT
SIGFPE SS$_FLTINE Inexact operation trap FPE_FLTINE_TRAP
SIGFPE SS$_FLTINV Invalid operation trap FPE_FLTINV_TRAP
SIGFPE SS$_FLTINV_F Invalid operation fault FPE_FLTINV_FAULT
SIGFPE SS$_FLTOVF Floating overflow trap FPE_FLTOVF_TRAP
SIGFPE SS$_FLTUND Floating undeflow trap FPE_FLTUND_TRAP
SIGFPE SS$_INTDIV Integer division by 0 FPE_INTDIV_TRAP
SIGFPE SS$_INTOVF Integer overflow FPE_INTOVF_TRAP
SIGFPE SS$_SUBRNG Subscript-range FPE_SUBRNG_TRAP
SIGHUP SS$_HANGUP Data set hangup --
SIGILL SS$_OPCDEC Reserved instruction ILL_PRIVIN_FAULT
SIGILL SS$_ROPRAND Reserved operand ILL_RESOP_FAULT
SIGINT SS$_CONTROLC OpenVMS Ctrl/C interrupt --
SIGIOT SS$_OPCCUS Customer-reserved opcode --
SIGKILL SS$_ABORT External signal only --
SIGQUIT SS$_CONTROLY The raise function --
SIGPIPE SS$_NOMBX No mailbox --
SIGPIPE C$_SIGPIPE Broken pipe --
SIGSEGV SS$_ACCVIO Length violation --
SIGSEGV SS$_CMODSUPR Change mode supervisor --
SIGSYS SS$_BADPARAM Bad argument to system call --
SIGTERM Not implemented -- --
SIGTRAP SS$_TBIT TBIT trace trap --
SIGTRAP SS$_BREAK Breakpoint fault instruction --
SIGUSR1 C$_SIGUSR1 The raise function --
SIGUSR2 C$_SIGUSR2 The raise function --
SIGWINCH C$_SIGWINCH The raise function --

4.3 Program Example

Example 4-1 shows how the signal , alarm , and pause functions operate. It also shows how to establish a signal handler to catch a signal, which prevents program termination.

Example 4-1 Suspending and Resuming Programs

/*    CHAP_4_SUSPEND_RESUME.C                                   */ 
 
/* This program shows how to alternately suspend and resume a   */ 
/* program using the signal, alarm, and pause functions.        */ 
 
#define SECONDS 5 
 
#include <stdio.h> 
#include <signal.h> 
 
int number_of_alarms = 5;       /*  Set alarm counter.            */ 
 
void alarm_action(int); 
 
main() 
{ 
    signal(SIGALRM, alarm_action); /*  Establish a signal handler. */ 
                                   /*  to catch the SIGALRM signal.*/ 
 
    alarm(SECONDS);     /* Set alarm clock for 5 seconds. */ 
 
    pause();    /*  Suspend the process until     * 
                 *  the signal is received.       */ 
} 
 
void alarm_action(int x) 
{ 
    printf("\t<%d\007>", number_of_alarms); /*  Print the value of  */ 
                                            /*  the alarm counter.  */ 
 
    signal(SIGALRM, alarm_action);      /*  Reset the signal.       */ 
 
    alarm(SECONDS);     /*  Set the alarm clock.      */ 
 
    if (--number_of_alarms)     /*  Decrement alarm counter.  */ 
        pause(); 
} 

Here is the sample output from Example 4-1:


$ RUN  EXAMPLE
       <5>   <4>   <3>   <2>   <1>


Chapter 5
Subprocess Functions

The HP C Run-Time Library (RTL) provides functions that allow you to create subprocesses from a HP C program. The creating process is called the parent and the created subprocess is called the child.

To create a child process within the parent process, use the exec functions ( execl , execle , execv , execve , execlp , and execvp ) and the vfork function. Other functions are available to allow the parent and child to read and write data across processes ( pipe ) and to allow for synchronization of the two processes ( wait ). This chapter describes how to implement and use these functions.

The parent process can execute HP C programs in its children, either synchronously or asynchronously. The number of children that can run simultaneously is determined by the /PRCLM user authorization quota established for each user on your system. Other quotas that may affect the use of subprocesses are /ENQLM (Queue Entry Limit), /ASTLM (AST Waits Limit), and /FILLM (Open File Limit).

This chapter discusses the subprocess functions. Table 5-1 lists and describes all the subprocess functions found in the HP C RTL. For more detailed information on each function, see the Reference Section.

Table 5-1 Subprocess Functions
Function Description
Implementation of Child Processes
system Passes a given string to the host environment to be executed by a command processor.
vfork Creates an independent child process.
The exec Functions
execl, execle, execlp
execv, execve, execvp
Passes the name of the image to be activated in a child process.
Synchronizing Process
wait , wait3 , wait4 , waitpid , Suspends the parent process until a value is returned from a child.
Interprocess Communication
pipe Allows for communication between a parent and child.

5.1 Implementing Child Processes in HP C

Child processes are created by HP C functions with the OpenVMS LIB$SPAWN RTL routine. (See the VMS Run-Time Library Routines Volume for information on LIB$SPAWN.) Using LIB$SPAWN allows you to create multiple levels of child processes; the parent's children can also spawn children, and so on, up to the limits allowed by the user authorization quotas discussed in the introduction to this chapter.

Child processes can only execute other HP C programs. Other native-mode OpenVMS languages do not share the ability of HP C to communicate between processes; if they do, they do not use the same mechanisms. The parent process must be run under an HP supported command-language interpreter (CLI), such as DCL. You cannot run the parent as a detached process or under control of a user-supplied CLI.

Enabling the DECC$DETACHED_CHILD_PROCESS feature logical allows child processes to be created as detached processes instead of subprocesses. This feature has only limited support. In some cases, the console cannot be shared between the parent process and the detached process, which can cause exec to fail.

Parent and child processes communicate through a mailbox as shown in Figure 5-1. This mailbox transfers the context in which the child will run. This context mailbox passes information to the child that it inherits from the parent, such as the names and file descriptors of all the files opened by the parent and the current location within those files. The mailbox is deleted by the parent when the child image exits.

Figure 5-1 Communications Links Between Parent and Child Processes


Note

The mailbox created by the vfork and exec functions is temporary. The logical name of this mailbox is VAXC$EXECMBX and is reserved for use by the HP C RTL.

The mailbox is created with a maximum message size and a buffer quota of 512 bytes each. You need the TMPMBX privilege to create a mailbox with these RTL functions. Since TMPMBX is the privilege required by the DCL commands PRINT and SUBMIT, most users on a system have this privilege. To see what system privileges you have, enter a SHOW PROCESS/PRIVILEGES command.

You cannot change the characteristics of these mailboxes. For more information on mailboxes, see the VMS I/O User's Reference Volume.

5.2 The exec Functions

There are six exec functions that you can call to execute an HP C image in the child process. These functions expect that vfork has been called to set up a return address. The exec functions will call vfork if the parent process did not.

When vfork is called by the parent, the exec function returns to the parent process. When vfork was called by an exec function, the exec function returns to itself, waits for the child to exit, and then exits the parent process. The exec function does not return to the parent process unless the parent calls vfork to save the return address.

In OpenVMS Version 7.2, the exec functions were enhanced to activate either executable images or DCL command procedures. If no file extension is specified in the file_name argument, the functions first search for the file with the .EXE file extension and then for the file with the .COM file extension. If both the executable image and the command procedure with the same name exist, you must explicitly specify the .COM file extension to force activating the command procedure.

For a DCL command procedure, the exec functions pass the first eight arg0, arg1, ..., arguments specified in the exec call to the command procedure as P1, P2, ... parameters, preserving the case.

Unlike UNIX based systems, the exec functions in the HP C RTL cannot always determine if the specified executable image or command procedure exists and can be activated and executed. Therefore, the exec functions might appear to succeed even though the specified file cannot be executed by the child process.

The status of the child process, returned to the parent process, indicates that the error occurred. You can retrieve this error code by using one of the functions from the wait family of functions.

Note

The vfork and exec functions in the HP C RTL on OpenVMS systems work differently than on UNIX systems:
  • On UNIX systems, vfork creates a child process, suspends the parent, and starts the child running where the parent left off.
  • On OpenVMS systems, vfork establishes context later used by an exec function, but it is the exec function, not vfork , that starts a process running the specified program.


For a progammer, the key differences are:
  • On OpenVMS systems, code between the the call to vfork and the call to an exec function runs in the parent process.

    On UNIX systems, this code runs in the child process.
  • On OpenVMS systems, the child inherits open file descriptors and so on, at the point where the exec function is called.

    On UNIX systems, this occurs at the point where vfork is called.

5.2.1 exec Processing

The exec functions use the LIB$SPAWN routine to create the subprocess and activate the child image within the subprocess. This child process inherits the parent's environment, including all defined logical names and command-line interpreter symbols.

By default, child processes also inherit the default (working) directory of their parent process. However, you can use the decc$set_child_default_dir function to set the default directory for a child process as it begins execution. For more information about the decc$set_child_default_dir function, see the Reference Section.

The exec functions use the logical name VAXC$EXECMBX to communicate between parent and child; this logical name must not exist outside the context of the parent image.

The exec functions pass the following information to the child:

When everything is transmitted to the child, exec processing is complete. Control in the parent process then returns to the address saved by vfork and the child's process ID is returned to the parent.

See Section 4.2.4 for a discussion of signal actions and the SIGCHLD signal.

5.2.2 exec Error Conditions

The exec functions will fail if LIB$SPAWN cannot create the subprocess. Conditions that can cause a failure include exceeding the subprocess quota or finding the communications by the context mailbox between the parent and child to be broken. Exceeding some quotas will not cause LIB$SPAWN to fail, but will put LIB$SPAWN into a wait state that can cause the parent process to hang. An example of such a quota is the Open File Limit quota.

You will need an Open File Limit quota of at least 20 files, with an average of three times the number of concurrent processes that your program will run. If you use more than one open pipe at a time, or perform I/O on several files at one time, this quota may need to be even higher. See your system manager if this quota needs to be increased.

When an exec function fails, a value of - 1 is returned. After such a failure, the parent is expected to call either the exit or _exit function. Both functions then return to the parent's vfork call, which returns the child's process ID. In this case, the child process ID returned by the exec function is less than zero. For more information about the exit function, see the Reference Section.


Previous Next Contents Index