Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

kill(1)

intro(2)

raise(2)

sigset(2)

sigcld(2)

wait2(2)

kill(2)

pause(2)

ptrace(2)

wait(2)



  signal(2)                           CLIX                           signal(2)



  NAME

    signal - Specifies what to do on receipt of a signal

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <signal.h>

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

  PARAMETERS

    sig    Specifies the target signal number.

    func   Specifies the address of a user function that will be invoked when
           the specified signal is received by the process, or a special value
           indicating that the signal should be ignored or handled by the
           system in the default manner.

  DESCRIPTION

    The signal() function allows the calling process to choose one of three
    ways to handle the receipt of a specific signal.  The sig parameter
    specifies the signal and the func parameters specifies the choice.

    The sig parameter can be assigned any one of the following except SIGKILL
    or SIGSTOP:

        SIGHUP    01      hangup
        SIGINT    02      interrupt
        SIGQUIT   03[1]   quit
        SIGILL    04[1]   illegal instruction (not reset when caught)
        SIGTRAP   05[1]   trace trap (not reset when caught)
        SIGEMT    07[1]   EMT instruction
        SIGFPE    08[1]   floating-point exception
        SIGKILL   09      kill (cannot be caught or ignored)
        SIGBUS    10[1]   bus error
        SIGSEGV   11[1]   segmentation violation
        SIGSYS    12[1]   bad argument to function
        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





  2/94 - Intergraph Corporation                                              1






  signal(2)                           CLIX                           signal(2)



        SIGUSR2   17      user-defined signal 2
        SIGCLD    18[2]   death of a child or child has stopped
        SIGCHLD   18[2]   death of a child or child has stopped
        SIGPWR    19[2]   power failure
        SIGURG    20[5]   urgent condition present on socket
        SIGIO     21[5]   I/O is possible on a socket (see fcntl(2))
        SIGPOLL   22[3]   selectable event pending
        SIGSTOP   23      stop (cannot be caught or ignored)
        SIGTSTP   24[4]   stop signal generated from keyboard
        SIGTTIN   25[4]   background read attempted from control terminal
        SIGTTOU   26[4]   background write attempted from control terminal
        SIGCONT   27[4]   continue if stopped (cannot be ignored)

    The func parameter is assigned one of three values:  SIG_DFL, SIG_IGN, or
    a function address.  The SIG_DFL and SIG_IGN signals are defined in the
    include file <signal.h>.  Each is a macro that expands to a constant
    expression of type pointer to function returning void and has a unique
    value that matches no declarable function.

    The actions prescribed by the values of func are as follows:

    SIG_DFL
           Terminates a process on receipt of a signal.  When the sig signal
           is received, the receiving process is to be terminated with all of
           the consequences outlined in the exit() function.  (See Note [1]
           below.)

    SIG_IGN
           Ignores the signal.  The sig signal is ignored.  Note that the
           SIGKILL and SIGSTOP signals cannot be ignored.

    function address
           Catches a signal.  When the sig signal is received, the receiving
           process will execute the signal-catching function pointed to by
           func.  The signal number sig is passed as the only argument to the
           signal-catching function.  Additional arguments are passed to the
           signal-catching function for hardware-generated signals.  Before
           entering the signal-catching function, the value of func for the
           caught signal is set to SIG_DFL unless the signal is SIGILL,
           SIGTRAP, or SIGPWR.

           On return from the signal-catching function, the receiving process
           resumes execution where it was interrupted.

           When a signal to be caught occurs during any of the following, the
           signal catching function is executed, and then the interrupted
           function may return a -1 to the calling process with errno set to
           EINTR:

           ⊕  A read(), write(), open(), or ioctl() function on a slow device
              (like a terminal, but not a file),



  2                                              Intergraph Corporation - 2/94






  signal(2)                           CLIX                           signal(2)



           ⊕  A pause() function,

           ⊕  A wait() function that does not return immediately, due to the
              existence of a previously stopped or zombie process,

           ⊕  Any other call that may sleep in the kernel.

           The signal() function does not catch an invalid function argument,
           func, and results are undefined when an attempt is made to execute
           the function at the bad address.

           Note that the SIGKILL and SIGSTOP signals cannot be caught.

    A call to signal() cancels a pending signal sig except for a pending
    SIGKILL or SIGSTOP signal.

    The signal() function fails if sig is an illegal signal number (including
    SIGKILL and SIGSTOP).

  Notes

    [1]   If SIG_DFL is assigned for these signals, in addition to the process
          being terminated, a ``core image'' is constructed in the current
          working directory of the process if the following conditions are
          met:

          The effective user ID and the real user ID of the receiving process
          are equal.

          An ordinary file named core exists and is writable or can be
          created.  If the file must be created, it will have the following
          properties:

          ⊕  A mode of 0666 modified by the file creation mask.  (See the
             umask() function).

          ⊕  A file owner ID that is the same as the effective user ID of the
             receiving process.

          ⊕  A file group ID that is the same as the effective group ID of the
             receiving process.

    [2]   For the signals SIGCLD and SIGPWR, func is assigned one of three
          values:  SIG_DFL, SIG_IGN, or a function address.  The actions
          prescribed by these values are:

          SIG_DFL
                 Ignores the signal.

          SIG_IGN
                 Ignores the signal.  Also, if sig is SIGCLD, the calling



  2/94 - Intergraph Corporation                                              3






  signal(2)                           CLIX                           signal(2)



                 process's child processes does not create zombie processes
                 when they terminate.  (See exit().)

          function address
                 Catches the signal.  If the signal is SIGPWR, the action to
                 be taken is the same as that described above for func equal
                 to function address.  The same is true if the signal is
                 SIGCLD with one exception:  while the process is executing
                 the signal-catching function, any received SIGCLD signals are
                 ignored.  (This is the default action.)

          In addition, SIGCLD affects the wait() and exit() functions as
          follows:

          wait()   If the func value of SIGCLD is set to SIG_IGN and a wait()
                   is executed, the wait() blocks until all of the calling
                   process's child processes terminate; it then returns a
                   value of -1 with errno set to ECHILD.

          exit()   If the func value of SIGCLD is set to SIG_IGN in the
                   exiting process's parent process, the exiting process does
                   not create a zombie process.

          When processing a pipeline, the shell makes the last process in the
          pipeline the parent of the preceding processes.  A process that may
          be piped into in this manner (and thus become the parent of other
          processes) should not set SIGCLD to be caught.

    [3]   SIGPOLL is issued when a file descriptor corresponding to a STREAMS
          (see the intro() function) file has a selectable event pending.  A
          process must specifically request that this signal be sent using the
          I_SETSIG ioctl() call.  Otherwise, the process will never receive
          SIGPOLL.

    [4]   If SIG_DFL is assigned for the SIGTSTP, SIGTTIN or SIGTTOU signals,
          the process enters the stopped state until a SIGCONT or SIGKILL
          signal is received.  If SIG_DFL is assigned for the SIGCONT signal
          and the process has entered the stopped state by receiving a stop
          signal (SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU), the process returns
          to its prior state.

    [5]   The default value for these signals is SIG_IGN.

  EXAMPLES

    1.  To request that the user function sigcld_hdlr be invoked when the
        calling process receives a SIGCLD signal:

        if (signal(SIGCLD, sigcld_hdlr) == SIG_ERR)
                perror("Signal for SIGCLD failed");




  4                                              Intergraph Corporation - 2/94






  signal(2)                           CLIX                           signal(2)



    2.  To request that SIGINT be ignored:

        if (signal(SIGINT, SIG_IGN) == SIG_ERR)
                perror("Signal for SIGINT failed");


  RETURN VALUES

    Upon successful completion, signal() returns the previous value of func
    for the specified signal sig.  Otherwise, a value of SIG_ERR is returned
    and errno is set to indicate the error.  The SIG_ERR signal is defined in
    the include file <signal.h>.

  ERRORS

    The signal() function fails under the following condition:

    [EINVAL]   The sig parameter is not a valid signal number, or is one of
               the signals whose signal action may not be altered

  RELATED INFORMATION

    Commands:  kill(1)

    Functions:  intro(2), raise(2), sigset(2), sigcld(2), wait2(2), kill(2),
    pause(2), ptrace(2), wait(2)




























  2/94 - Intergraph Corporation                                              5




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026