sig-atomic-t

Exactly which variables need to be sig_atomic_t in the context of signal handling?

非 Y 不嫁゛ 提交于 2019-12-01 08:43:55
问题 Here is a simple toy program that uses volatile sig_atomic_t . #include <stdio.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> #define UNUSED(x) (void) (x) volatile sig_atomic_t quit; void sigusr1_handler(int sig) { UNUSED(sig); write(1, "handler\n", 8); quit = 1; } int main() { struct sigaction sa; sa.sa_handler = sigusr1_handler; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); if (sigaction(SIGUSR1, &sa, NULL) == -1) { perror("sigaction"); return 1; } quit = 0; while (!quit) ;