进程间通信-信号

进程间通信

#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void ouch(int sig)
{
    printf("\nOUCH! - I got signal %d\n", sig);
    // 恢复终端中断信号SIGINT的默认行为
    (void) signal(SIGINT, SIG_DFL);
}
int main()
{
    // 改变终端中断信号SIGINT的默认行为,使之执行ouch函数
    // 而不是默认终止程序的执行
    (void) signal(SIGINT, ouch);
    while(1)
    {
        printf("Hello World!\n");
        sleep(1);
    }
    return 0;
}

信号的默认处理方式
https://www.cnblogs.com/jiangzhaowei/p/4113644.html

posted @ 2019-10-15 17:58  hostid  阅读(98)  评论(0编辑  收藏  举报