zoukankan      html  css  js  c++  java
  • 信号补充

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>
    #include <unistd.h>
    #include <string.h>
    #include <strings.h>
    #include <errno.h>
    
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <fcntl.h>
    #include <signal.h>
    
    void doSig(int num)
    {
        printf("i am doSig
    ");
        printf("%d
    ",num);
    }
    
    void printSigset(const sigset_t *s)
    {
        for(int i = 1;i < 32;i++)
        {
            if(sigismember(s,i) == 1)
                printf("1");
            else
                printf("0");
        }    
        printf("
    ");
    }
    
    int main(int argc, char **argv)
    {
        sigset_t p;    
        printf("sizeof sigset_t = %d
    ",sizeof(sigset_t));
        
        sigemptyset(&p);
        sigaddset(&p,SIGQUIT);// ctrl + z
        sigprocmask(SIG_BLOCK,&p,NULL);// 设置阻塞信号集
    
        struct sigaction s;
        s.sa_handler = doSig;
        s.sa_flags = 0;
        sigemptyset(&s.sa_mask); // sa_mask 时一个临时的值,执行完handler函数之后,就不起作用了 mask |= sa_mask
    
        sigaction(SIGINT,&s,NULL);
    
        while(1)
        {
            sleep(1);
            sigpending(&p);    
            printSigset(&p);
        }
        
        return 0;
    }
    sizeof sigset_t = 128
    0000000000000000000000000000000
    0000000000000000000000000000000
    0000000000000000000000000000000
    0000000000000000000000000000000
    0000000000000000000000000000000
    ^0010000000000000000000000000000
    0010000000000000000000000000000
    0010000000000000000000000000000
    0010000000000000000000000000000
    0010000000000000000000000000000
    ^^0010000000000000000000000000000
    0010000000000000000000000000000
    0010000000000000000000000000000
    0010000000000000000000000000000
    ^Ci am doSig
    2
    0010000000000000000000000000000
    0010000000000000000000000000000
    0010000000000000000000000000000
    0010000000000000000000000000000

  • 相关阅读:
    tomcat启动脚本
    libcrypto.so.1.0.0内容丢失导致sshd无法运行解决方案
    linux最小安装
    linux下文件删除的原理
    Web服务器磁盘满故障深入解析
    入驻博客园,新的开始!!!
    其实我们都可以变得更加优秀!
    我的未来在哪里呢!
    学会选择
    SpringBoot+vue.js如何通过post方式实现导出excel
  • 原文地址:https://www.cnblogs.com/xiangtingshen/p/11954311.html
Copyright © 2011-2022 走看看