Linux System Programming · beginner · ~8 min

Common signals: SIGINT, SIGTERM, SIGKILL, SIGSEGV, SIGALRM

Recognise the five signals you'll encounter every day and know their default action.

Lesson

You will meet these five constantly. Memorise this table.

Signal Number Sent by Default action
SIGINT 2 terminal Ctrl+C terminate
SIGTERM 15 kill <pid> (default), systemd terminate
SIGKILL 9 kill -9 <pid>, kernel last resort terminate (uncatchable)
SIGSEGV 11 kernel, on bad memory access terminate + core dump
SIGALRM 14 alarm(), setitimer() terminate

Bonus to know:

  • SIGHUP (1) — "your terminal hung up." Daemons traditionally re-read config on this.
  • SIGUSR1 / SIGUSR2 — reserved for your application to use freely.
  • SIGCHLD — a child process changed state. Server processes use this to reap zombies.

Code examples

#include <signal.h>
/* The number-to-name mapping is also exposed at runtime: */
#include <string.h>
#include <stdio.h>
int main(void) {
    for (int s = 1; s <= 15; s++)
        printf("%2d %s\n", s, strsignal(s));
    return 0;
}

Common mistakes

  • Trying to catch SIGKILL "just in case." It can't be caught — the kernel won't even deliver it to your handler.
  • Confusing SIGTERM (polite "please stop") with SIGKILL (immediate, mandatory). Always send SIGTERM first.

Summary

SIGINT = Ctrl+C, SIGTERM = polite kill, SIGKILL = unstoppable kill, SIGSEGV = bad pointer, SIGALRM = timer fired. SIGUSR1/SIGUSR2 are yours to use freely.

Practice with these exercises