zoukankan      html  css  js  c++  java
  • linux 信号

    参考链接:  

    信号内容具体分析:   http://www.cnblogs.com/hoys/archive/2012/08/19/2646377.html

    信号的例子介绍:  http://blog.csdn.net/jnu_simba/article/details/8947652

     信号值位于SIGRTMIN和SIGRTMAX为可靠信号,也为实时信号,支持排队操作, 其余为非可靠信号。

    信号的简单例子:

    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <signal.h>
    
    
    
    void SigSendTestMail(int signo)
    {
       printf("get signal:%d
    ", signo);
    }
    
    
    
    int main(int argc, char const *argv[])
    {
        
        printf("SIGRTMIN val:%d
    ", SIGRTMIN);
        struct sigaction          act;
        act.sa_handler = SigSendTestMail;
        act.sa_flags   = 0;
        sigemptyset(&act.sa_mask);
        sigaction(SIGRTMIN+10, &act, 0);
    
    
    
        act.sa_handler = SigSendTestMail;
        act.sa_flags   = 0;
        sigemptyset(&act.sa_mask);
        sigaction(SIGRTMIN+11, &act, 0);
    
    
    
        act.sa_handler = SigSendTestMail;
        act.sa_flags   = 0;
        sigemptyset(&act.sa_mask);
        sigaction(SIGRTMIN+12, &act, 0);
    
    
    
    
        while(1) {
            sleep(3);
        }
    
        return 0;
    }
       

    sigqueue结构体的使用:

    #include <stdio.h>
    #include <unistd.h>
    #include <signal.h>
    #include <stdlib.h>
    
    void sighandler(int signo, siginfo_t *info,void *ctx);
    //给自身传递信息
    int main(void)
    {
    
        struct sigaction act;
        act.sa_sigaction = sighandler;
        sigemptyset(&act.sa_mask);
        act.sa_flags = SA_SIGINFO;//信息传递开关
        if(sigaction(42,&act,NULL) == -1){
            perror("sigaction error");
            exit(EXIT_FAILURE);
        }
        sleep(2);
        union sigval mysigval;
        mysigval.sival_int = 100;
        if(sigqueue(getpid(),42,mysigval) == -1){
            perror("sigqueue error");
            exit(EXIT_FAILURE);
        }
        return 0;
    }
    
    void sighandler(int signo, siginfo_t *info,void *ctx)
    {
        //以下两种方式都能获得sigqueue发来的数据
        printf("receive the data from siqueue by info->si_int is %d
    ",info->si_int);
        printf("receive the data from siqueue by info->si_value.sival_int is %d
    ",info->si_value.sival_int);
    
    }

      

  • 相关阅读:
    linux下配置php的一些信息
    前端学习
    Verilog笔记.3.有限状态机
    Verilog笔记.2.数字逻辑电路
    Verilog笔记.1.基本语法
    python3爬虫.4.下载煎蛋网妹子图
    python3爬虫.3.下载网页图片
    python3爬虫.2.伪装浏览器
    python3爬虫.1.简单的网页爬虫
    python3学习笔记.3.条件控制与循环
  • 原文地址:https://www.cnblogs.com/hzijone/p/7591191.html
Copyright © 2011-2022 走看看