44 lines
1001 B
C
44 lines
1001 B
C
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <stdbool.h>
|
|
|
|
#define SLEEP_TIME 1
|
|
|
|
volatile int x;
|
|
|
|
void sigint_handler(int signal)
|
|
{
|
|
puts("sigint handler");
|
|
sleep(SLEEP_TIME);
|
|
}
|
|
|
|
void sigusr1_handler(int signal)
|
|
{
|
|
puts("sigusr1 handler");
|
|
kill(getpid(), SIGINT);
|
|
}
|
|
|
|
#define DO_OR_FAIL(cond) if (cond) return EXIT_FAILURE
|
|
int main()
|
|
{
|
|
struct sigaction sa_int = {
|
|
.sa_handler = sigint_handler
|
|
};
|
|
struct sigaction sa_usr1 = {
|
|
.sa_handler = sigusr1_handler
|
|
};
|
|
struct sigaction old_sa = {0};
|
|
DO_OR_FAIL(sigemptyset(&sa_int.sa_mask));
|
|
DO_OR_FAIL(sigemptyset(&sa_usr1.sa_mask));
|
|
DO_OR_FAIL(sigaddset(&sa_int.sa_mask, SIGINT));
|
|
DO_OR_FAIL(sigaddset(&sa_usr1.sa_mask, SIGUSR1));
|
|
DO_OR_FAIL(sigaction(SIGINT, &sa_int, &old_sa));
|
|
DO_OR_FAIL(sigaction(SIGUSR1, &sa_usr1, NULL));
|
|
while (true) {
|
|
x++; // чтобы не соптимизировался
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|