Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <signal.h>
    void ( *signal(int sig, void (*func)(int)) )( int );

Description:
    The signal function is used to specify an action to take place when
    certain conditions are detected while a program executes.  These
    conditions are defined to be:

    SIGABRT
        abnormal termination, such as caused by the  abort function

    SIGBREAK
        an interactive attention (CTRL/BREAK on keyboard) is signalled

    SIGFPE
        an erroneous floating-point operation occurs (such as division by
        zero, overflow and underflow)

    SIGILL
        illegal instruction encountered

    SIGINT
        an interactive attention (CTRL/C on keyboard) is signalled

    SIGSEGV
        an illegal memory reference is detected

    SIGTERM
        a termination request is sent to the program

    SIGUSR1
        OS/2 process flag A via DosFlagProcess

    SIGUSR2
        OS/2 process flag B via DosFlagProcess

    SIGUSR3
        OS/2 process flag C via DosFlagProcess

    An action can be specified for each of the conditions, depending upon
    the value of the func argument:

    function
        When func is a function name, that function will be called
        equivalently to the following code sequence.


                 /* "sig_no" is condition being signalled */
                 signal( sig_no, SIG_DFL );
                 (*func)( sig_no );

        The func function may terminate the program by calling the  exit or
         abort functions or call the  longjmp function.  Because the next
        signal will be handled with default handling, the program must again
        call signal if it is desired to handle the next condition of the
        type that has been signalled.

        After returning from the signal-catching function, the receiving
        process will resume execution at the point at which it was
        interrupted.

        The signal catching function is described as follows:


                 void func( int sig_no )
                 {

                     /* body of function */

                 }

        Since signal-catching functions are invoked asynchronously with
        process execution, the type  sig_atomic_t may be used to define
        variables on which an atomic operation (e.g., incrementation,
        decrementation) may be performed.

    SIG_DFL
        This value causes the default action for the condition to occur.

    SIG_IGN
        This value causes the indicated condition to be ignored.

    When a condition is detected, it may be handled by a program, it may be
    ignored, or it may be handled by the usual default action (often causing
    an error message to be printed upon the stderr stream followed by
    program termination).

    When the program begins execution, the equivalent of


             signal( SIGABRT, SIG_IGN );
             signal( SIGFPE, SIG_DFL );
             signal( SIGILL, SIG_DFL );
             signal( SIGINT, SIG_IGN );
             signal( SIGSEGV, SIG_DFL );
             signal( SIGTERM, SIG_DFL );

    is executed.

    A condition can be generated by a program using the  raise function.

Returns:
    A return value of  SIG_ERR indicates that the request could not be
    handled, and  errno is set to the value  EINVAL.

    Otherwise, the previous value of func for the indicated condition is
    returned.

See Also:
    raise

Example:
    #include <signal.h>

    sig_atomic_t signal_count;

    void MyHandler( int sig_number )
      {
         ++signal_count;
      }

    void main()
      {
        signal( SIGFPE, MyHandler );   /* set own handler */
        signal( SIGABRT, SIG_DFL );    /* Default action */
        signal( SIGFPE, SIG_IGN );     /* Ignore condition */
      }

Classification:
    ANSI

Systems:
    All

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson