920 B
920 B
Signal Handler
Overview
This project demonstrates how to handle UNIX signals in C using sigaction.
It specifically intercepts SIGINT and SIGUSR1 and prints messages when these signals are received.
Features
- Intercepts SIGINT (usually generated with
Ctrl + C) and SIGUSR1`. - Prints a custom message for each signal.
- Tracks the number of
SIGINTsignals received and terminates after a defined count. - Demonstrates proper use of:
sigaction()instead ofsignal()for consistent behavior.volatile sig_atomic_tfor safe signal state handling.
Build
make
Run
./signal_handler
Test
- Open another terminal and run:
kill -USR1 <PID>
where <PID> is the process ID of signal_handler.
- Press
Ctrl + Cin the terminal running the program to sendSIGINT.
Clean
make clean