#define _XOPEN_SOURCE 700 #include #include #include #include #include #include void handler(int sig) { printf("sig is %d, handler ...\n", sig); // exit(0); } int main() { struct sigaction sa; sa.sa_handler = handler; sigfillset(&sa.sa_mask); // sa.sa_flags = 0; // 信号只能被处理一次,下次恢复默认行为 // sa.sa_flags |= SA_RESETHAND; // 重置默认的信号处理行为 sigaction(SIGINT, &sa, NULL); while (1) ; return 0; }