raise function(Raise Signal) in C Language – example and detail

In the C Programming Language, the increase function raises the signal represented through 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 increase feature returns zero if successful and a nonzero cost if unsuccessful.

Required Header

In the C Language, the required header for the elevate feature is:

#include <signal.h>

Applies To

In the C Language, the elevate feature 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 comparable to the elevate function:

abort function <stdlib.h>

See Also

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

signal function <signal.h>