totn C Functions

C Language: raise function
(Raise Signal)

In the C Programming Language, the raise function raises the signal represented by sig.

Syntax

The syntax for the raise function in the C Language is:

int raise(int sig);

Parameters or Arguments

sig
The numeric value of the signal to raise.

Returns

The raise function returns zero if successful and a nonzero value if unsuccessful.

Required Header

In the C Language, the required header for the raise function is:

#include <signal.h>

Applies To

In the C Language, the raise function can be used in the following versions:

  • ANSI/ISO 9899-1990

raise Example

/* Example using raise by TechOnTheNet.com */

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

void signal_handler(int signal)
{
    /* Display a message indicating we have received a signal */
    if (signal == SIGUSR1) printf("Received a SIGUSR1 signal\n");

    /* Exit the application */
    exit(0);
}

int main(int argc, const char * argv[])
{
    /* Display a message indicating we are registering the signal handler */
    printf("Registering the signal handler\n");

    /* Register the signal handler */
    signal(SIGUSR1, signal_handler);

    /* Display a message indicating we are raising a signal */
    printf("Raising a SIGUSR1 signal\n");

    /* Raise the SIGUSR1 signal */
    raise(SIGUSR1);

    /* Display a message indicating we are leaving main */
    printf("Finished main\n");

    return 0;
}

When compiled and run, this application will output:

Registering the signal handler
Raising a SIGUSR1 signal
Received a SIGUSR1 signal

Similar Functions

Other C functions that are similar to the raise function:

See Also

Other C functions that are noteworthy when dealing with the raise function: