30 lines
568 B
C
30 lines
568 B
C
#define _XOPEN_SOURCE 700
|
|
#include <stdio.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
|
|
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;
|
|
} |