This directory contains examples demonstrating different aspects of signal handling in the event loop library.
Demonstrates basic signal handling with SIGINT, SIGTERM, and SIGUSR1 (on Unix systems).
gcc -I../include -o signal_example signal_example.c ../src/*.c
./signal_exampleShows how to handle multiple signals with custom data and counting.
- Handles SIGUSR1 and SIGUSR2 with a shared counter
- Demonstrates graceful termination with SIGTERM
gcc -I../include -o signal_multiple signal_multiple.c ../src/*.c
./signal_multipleImplements a graceful shutdown pattern:
- First Ctrl+C initiates graceful shutdown
- Second Ctrl+C forces immediate shutdown
- Demonstrates proper cleanup of resources
gcc -I../include -o signal_shutdown signal_shutdown.c ../src/*.c
./signal_shutdown- Uses signalfd() for efficient signal handling
- All POSIX signals are supported
- Signals are queued and delivered reliably
- Uses kqueue with EVFILT_SIGNAL
- All POSIX signals are supported
- Signals are integrated with the kqueue event mechanism
- Limited to console control signals:
- SIGINT (Ctrl+C)
- SIGBREAK (Ctrl+Break)
- SIGTERM (Console close)
- Uses SetConsoleCtrlHandler() internally
- Keep signal handlers minimal and fast
- Use the event loop to defer complex processing
- Always check return values from signal-related functions
- Clean up signal handlers before destroying the event loop
- Avoid installing the same signal handler multiple times