


      SIGNAL(2)                   (UNIX 5.0)                  SIGNAL(2)



      NAME
           signal - specify what to do upon receipt of a signal

      SYNTAX
           #include <sys/signal.h>

           int (*signal (sig, func))()
           int sig;
           int (*func)();

      DESCRIPTION
           Signal allows the calling process to choose one of three
           ways in which it is possible to handle the receipt of a
           specific signal.  Sig specifies the signal and func
           specifies the choice.

           Sig can be assigned any one of the following except SIGKILL:

           SIGHUP         01  hangup
           SIGINT         02  interrupt
           SIGQUIT        03  quit
           SIGILL         04  illegal instruction  (not reset when caught)
           SIGTRAP        05  trap 21 (trace trap) (not reset when caught)
           SIGIOT         06  unused
           SIGEMT         07  trap 3 (emulator trap)
           SIGFPE         08  floating point exception
           SIGKILL        09  kill (cannot be caught or ignored)
           SIGBUS         10  bus error
           SIGSEGV        11  segmentation violation
           SIGSYS         12  bad argument to system call
           SIGPIPE        13  write on a pipe with no one to read it
           SIGALRM        14  alarm clock
           SIGTERM        15  software termination signal
           SIGUSR1        16  user-defined signal 1
           SIGUSR2        17  user-defined signal 2
           SIGCLD         18  child died
           SIGPWROFF      19  power went off
           SIGIO          59  i/o is possible on a descriptor (see the c_lflag lintrup in termio(7))
           SIGRBUG        100 trap 0, enter system debugger (privilege req'd)
           SIGDEBUG       101 trap 1, enter program debugger
           SIGTRAP4       104 trap 4, reserved
           SIGTRAP5       105 trap 5, reserved
           SIGTRAP6       106 trap 6, reserved
           SIGTRAP7       107 trap 7, reserved
           SIGTRAP8       108 trap 8, reserved
           SIGTRAP9       109 trap 9, reserved
           SIGTRAP10      110 trap 10,reserved
           SIGTRAP11      111 trap 11,reserved
           SIGTRAP12      112 trap 12,reserved
           SIGTRAP13      113 trap 13,reserved
           SIGTRAP14      114 trap 14, user-defined trap1
           SIGTRAP15      115 trap 15, user-defined trap2



      Page 1                                         (73 A2 02MTA REV1)






      SIGNAL(2)                   (UNIX 5.0)                  SIGNAL(2)



           SIGINTOVER     116 trap 16, integer overflow
           SIGINTDIVZERO  117 trap 17, divide by zero
           SIGREALOVER    118 trap 18, real overflow
           SIGREALUNDER   119 trap 19, real underflow
           SIGREALDIVZERO 120 trap 20, real div by 0
           SIGTRAP21      121 trap 21, reserved
           SIGTRAP22      122 trap 22, reserved
           SIGTRAP23      123 trap 23, reserved
           SIGTRAP24      124 trap 24, reserved
           SIGTRAP25      125 trap 25, reserved
           SIGTRAP26      126 trap 26, reserved
           SIGTRAP27      127 trap 27, reserved
           SIGTRAP28      128 trap 28, reserved
           SIGTRAP29      129 trap 29, reserved
           SIGTRAP30      130 trap 30, reserved
           SIGPWRON       131 power went back on
           SIGBOUNDS      132 array bounds exceeded

           Func is assigned one of four values:  SIG_DBG, SIG_DFL,
           SIG_IGN, or a function address.  The actions prescribed by
           these values of are as follows:

             SIG_DBG -  suspend process and enter debugger (debug_).

             SIG_DFL -  terminate process upon receipt of a signal
                     Upon receipt of the signal sig, the receiving
                     process is to be terminated with all of the
                     consequences outlined in exit(2).

             SIG_IGN -  ignore signal
                     The signal sig is to be ignored.

                     Note: the signal SIGKILL cannot be ignored.

             function address -  catch signal
                     Upon receipt of the signal sig, the receiving
                     process is to execute the signal-catching function
                     pointed to by func.  The signal number sig will be
                     passed as the only argument to the signal-catching
                     function.  Before entering the signal-catching
                     function, the value of func for the caught signal
                     will be set to its default value. The default
                     signal for SIGQUIT, SIGILL, SIGBUS, and SIGSEGV is
                     SIG_DBG.  All other signals have a default setting
                     of SIG_DFL.

                     Upon return from the signal-catching function, the
                     receiving process will resume execution at the
                     point it was interrupted.

                     When a signal that is to be caught occurs during a
                     read, a write, an open, or an ioctl system call on



      Page 2                                         (73 A2 02MTA REV1)






      SIGNAL(2)                   (UNIX 5.0)                  SIGNAL(2)



                     a slow device (like a terminal; but not a file),
                     during a pause system call, or during a wait
                     system call that does not return immediately due
                     to the existence of a previously stopped or zombie
                     process, the signal catching function will be
                     executed and then the interrupted system call will
                     return a -1 to the calling process with errno set
                     to EINTR.

             SIGFPE
                     SIGREALOVER (118), SIGREALUNDER (119), and
                     SIGREALDIVZERO (120) work in conjunction with
                     SIGFPE (08). When SIGFPE is set, 118, 119, and 120
                     are set to the same value.  When a hardware
                     floating-point exception occurs, one of 118, 119,
                     or 120 is generated.  A process never receives
                     SIGFPE as a result of a floating-point exception.

             A call to signal cancels a pending signal sig except for a
             pending SIGKILL signal.

             Signal will fail if one or more of the following are true:

                  Sig is an illegal signal number, including SIGKILL.
                  [EINVAL]

                  Func points to an illegal address.  [EFAULT]

      RETURN VALUE
           Upon successful completion, signal returns the previous
           value of func for the specified signal sig.  Otherwise, a
           value of -1 is returned and errno is set to indicate the
           error.

      SEE ALSO
           kill(1), kill(2), pause(2), wait(2), setjmp(3C).

      NOTES  (Bull-SPS9)
           The handler routine can be declared:

               handler(sig, code, scp)
               int sig, code;
               struct sigcontext *scp;

           Here sig is the signal number, into which the hardware
           faults and traps are mapped as defined below. Code is a
           parameter which is a constant as given below.

           The following defines the mapping of hardware traps to
           signals and codes.  All of these symbols are defined in
           <signal.h>:




      Page 3                                         (73 A2 02MTA REV1)






      SIGNAL(2)                   (UNIX 5.0)                  SIGNAL(2)



                   Hardware condition              Signal             Code

                Arithmetic traps:
                   Integer overflow                SIGINTOVER         FPE_INTOVF_TRAP
                   Integer division by zero        SIGINTDIVZERO      FPE_INTDIV_TRAP
                   Floating overflow trap          SIGREALOVER        FPE_FLTOVF_TRAP
                   Floating division by zero       SIGREALDIVZERO     FPE_FLTDIV_TRAP
                   Floating underflow trap         SIGREALUNDER       FPE_FLTUND_TRAP
                   Subscript-range                 SIGBOUNDS          FPE_SUBRNG_TRAP
                Length access control              SIGSEGV
                Invalid instruction                SIGILL             ILL_RESAD_FAULT
                Priv. Instruction Violation        SIGILL             ILL_PRIVIN_FAULT
                Trace pending                      SIGTRAP
                Alignment Violation                SIGBUS             BUS_ALIGN_FAULT

           Scp is a pointer to the sigcontext structure (defined in
           <signal.h>), used to restore the context from before the
           signal.

                struct sigcontext {
                    int           sc_onstack;         /* ignored */
                    int           sc_mask[3];         /* signal mask to restore */
                    char          sc_instruction[8];  /* interrupted/faulted instruction */
                    stateRecord   sc_pstate;          /* see below */
                };






























      Page 4                                         (73 A2 02MTA REV1)






      SIGNAL(2)                   (UNIX 5.0)                  SIGNAL(2)



           The stateRecord (defined in <sys/procstate.h>) contained in
           the sigcontext structure defines the state of the process at
           the point of interruption.

                typedef struct {                      /* Process State */
                    int           registers[16];      /* registers */
                    int           pc;                 /* program counter */
                    unsigned int  parent;             /* UM process id */
                    double        Traps;              /* CPU trap enable bits */
                    int           ProcRunTime;        /* CPU time in nanoseconds */
                    int           status;             /* process status */
                    int           priority;           /* process priority */
                    int           msgWait;            /* not used */
                    int           numFaults;          /* cumulative page fault count */
                    int           stateUnused;        /* not used */
                    double        codeFile;           /* FID of code file */
                    double        dataFile;           /* FID of data file */
                    double        queueFile;          /* FID of queue file */
                    int           extra[32];          /* not used */
                  } stateRecord;

           The handler is free to use any of the fields provided to
           determine its course of action in dealing with this signal.
           The only fields that are restored when the handler returns,
           and thereby affect the execution of the process, are the
           registers and pc fields of the stateRecord structure and the
           sc_mask of the sigcontext structure.

           For example, for floating point traps the handler can
           inspect the sc_instruction bytes and modify the appropriate
           registers.  Then the handler could increment the pc by the
           appropriate number of bytes and return.  This would result
           in the registers being restored and execution continuing at
           the new pc.





















      Page 5                                         (73 A2 02MTA REV1)



