首页 > 系统服务 > 详细

一、进程与信号不可靠问题

时间:2016-09-11 17:10:01      阅读:184      评论:0      收藏:0      [点我收藏+]

进程在处理过程中是否还可以接收处理信号,相同信号/不同信号

范列

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

void set_signal(int signo)
{
    if(signo == SIGINT)
    {
        printf("%d catch SIGINT\n",getpid());
        sleep(5);
        printf("process the sigint finished\n");
    }
    if(signo==SIGTSTP)
    {
        printf("%d catch SIGTSTP\n",getpid());
        sleep(5);
        printf("process the sigtstp finished\n");
    }
}

int main()
{
    if(signal(SIGINT,set_signal)==SIG_ERR)
    {
        printf("signal error\n");
        return 1;
    }
    if(signal(SIGTSTP,set_signal)==SIG_ERR)
    {
        printf("signal error\n");
        return 1;
    }
    
    //暂停等待信号
    while(1) pause(); 
}

编译执行

进程处理中中发送相同信号,先发送ctrl+c 在发送ctrl+c
^C3267 catch SIGINT
^Cprocess the sigint finished
3267 catch SIGINT
process the sigint finished

进程处理中发送不同信号,先发送ctrl+c 在发送ctrl+z
^C3267 catch SIGINT
^Z3267 catch SIGTSTP
process the sigtstp finished
process the sigint finished

结论

进程处理中发送相同信号/不同信号仍然会处理,但是超过2次进程就会屏蔽

 

一、进程与信号不可靠问题

原文:http://www.cnblogs.com/peixiguang/p/5862042.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!