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

raise(signo) is shorthand for kill(getpid(), signo) — it sends the named signal to the calling process (or in a threaded program, to the calling thread). Common uses:

  • Re-raising a fatal signal after cleanup so the parent sees the right exit cause.
  • Triggering your own SIGINT handler for testing.
  • Returning the "correct" exit status to a parent that inspects 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

  • Calling raise(SIGKILL) thinking you'll catch it inside the same program. SIGKILL is uncatchable; you'll just die.

Summary

raise(signo) sends a signal to yourself — useful for cleanup-then-re-raise patterns and for testing your own handlers.

Practice with these exercises