, : sigaction (2)
, , , - :
CTRL + c:
#include <signal.h>
#include <stdio.h>
void handle_signal(int);
int main(int argc, char* argv[])
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_signal;
sigaction(SIGINT, &sa, NULL);
...
}
void handle_signal(int signal)
{
switch (signal) {
case SIGINT:
your_cleanup_function();
break;
default:
fprintf(stderr, "Caught wrong signal: %d\n", signal);
return;
}
}
, (7), .