Linux System Programming · beginner · ~6 min

raise() — sending a signal to yourself

Use raise() to signal the calling process from inside its own code.

Lesson

What raise() does

raise(signo) sends the named signal to the program that calls it.

It is shorthand for kill(getpid(), signo). In a multi-threaded program, the signal goes to the calling thread, not the whole process.

Common uses

  • Re-raise a fatal signal after cleanup. This lets the parent process see the correct cause of death.
  • Trigger your own handler for testing. For example, fire your SIGINT handler on demand.
  • Report the right exit status to a parent that inspects the result with WIFSIGNALED.

Code examples

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

int main(void) {
    printf("about to raise SIGUSR1\n");
    raise(SIGUSR1);     /* default action: terminate */
    printf("you won't see this\n");
    return 0;
}

Common mistakes

  • Trying to catch SIGKILL in the same program. Calling raise(SIGKILL) and expecting to handle it will not work. SIGKILL cannot be caught or blocked. The process simply terminates.

Summary

  • raise(signo) sends a signal to the calling process (or thread).
  • It is equivalent to kill(getpid(), signo).
  • Useful for the cleanup-then-re-raise pattern and for testing your own handlers.
  • SIGKILL is uncatchable, so you cannot handle a raise(SIGKILL).

Practice with these exercises