系统编程———信号屏蔽

本文探讨了信号屏蔽(信号搁置)与忽略信号的区别,指出信号屏蔽不删除信号,而是将其存入搁置信号集,而忽略信号会直接删除信号。同时介绍了信号屏蔽函数sigprocmask的使用,包括级联方式和覆盖方式。
摘要由CSDN通过智能技术生成

信号屏蔽

信号屏蔽(信号搁置)与忽略信号的区别

1.信号屏蔽并没有删除信号,只是将未处理的信号存入了搁置信号集,而忽略信号是将未处理的信号直接删除

信号屏蔽函数:

int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
@how:

1.级联方式:

在原有基础上加减: 5 + 1 = 6, 6 - 1 = 5
SIG_BLOCK +信号,屏蔽
The set of blocked signals is the union of the current set and the set argument.
SIG_UNBLOCK -信号,解屏蔽

2.覆盖方式

SIG_SETMASK:覆盖方式, int a = 100; int olda = a; a = 200;

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>

void sigfun(int args)
{
   
    printf("%s %d start\n", __func__, __LINE__);
    if (SIGINT == args)
        printf("this signal is SIGINT\n"); //ctrl+c
    else if (SIGQUIT == args)
        printf("this signal is SIGQUIT\n"); //ctrl+/
    printf("%s %d stop\n", __func__, __LINE__);
}
int main()
{
   
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值