C signal.h Functions

Definition
Definition and Usage
<signal.h> is the C header for simple signal handling. Its two core functions are signal(), which chooses how a signal is handled, and raise(), which asks the current program to handle a signal now.
This page is the catalog for both tutorials. Start from the beginner overview if signal numbers and handlers are new, then open each function guide for syntax, return values, and three examples.
Need the model first?
Read C Signals for SIGINT, SIG_DFL, SIG_IGN, and the tiny-handler pattern.
Quick choice
Choose a Function by Job
| I want to... | Start with |
|---|---|
| Install or change a handler | signal() |
| Ignore a signal | signal(sig, SIG_IGN) |
| Restore the default action | signal(sig, SIG_DFL) |
| Test a handler in the same program | raise() |
Index
C signal.h Functions Index
Remember
Key Takeaways
- Handlers stay tiny. Prefer a
volatile sig_atomic_tflag over complex work inside the handler. - Check SIG_ERR and raise(). Installation and delivery both have failure results.
- Behavior varies by system. Keep examples portable and avoid assuming advanced POSIX semantics.
Frequently Asked Questions
It declares signal() and raise(), plus macros such as SIGINT, SIGTERM, SIG_DFL, SIG_IGN, and SIG_ERR.
Start with signal() to install a tiny handler, then use raise() to test it.
Set a volatile sig_atomic_t flag and return. Avoid printf, malloc, and most other library calls inside the handler.
Call signal(sig, SIG_IGN). Use SIG_DFL to restore the default action.
signal() changes the disposition. raise() asks the current program to handle a signal now.
Start with raise()
Learn how to send a signal to the current program.
8 people found this page helpful
