qfedu-linux-advanced-level/day3/t21.c

47 lines
1.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
int main(int argc, char const *argv[])
{
// 定义一个信号集
sigset_t set;
// 所有信号填充到信号集
// sigfillset(&set);
// printf("SIGINT in set ? %d\n", sigismember(&set, SIGINT));
// 清空set集
sigemptyset(&set);
printf("SIGINT in set ? %d\n", sigismember(&set, SIGINT));
// 将SIGINT添加到set集合中 (Ctrl+C触发中断信号终止进程)
sigaddset(&set, SIGINT);
// 将SIGTSTP添加到set集和中 (终端停止信号)
sigaddset(&set, SIGTSTP);
if (sigismember(&set, SIGINT))
{
printf("SIGINT是在set集合中\n");
}
else
{
printf("SIGINT不在set集合中\n");
}
// 将SIGINT从集合中删除
sigdelset(&set, SIGINT);
if (sigismember(&set, SIGINT))
{
printf("SIGINT是在set集合中\n");
}
else
{
printf("SIGINT不在set集合中\n");
}
return 0;
}