您的位置:首页 > 运维架构 > Linux

linux 信号

2016-06-10 07:40 363 查看
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <iostream>
#include <unistd.h>
#include <signal.h>

using namespace std;

typedef void (*sighandler_t)(int);
void handler( int sig )
{
cout << "sig = " << sig << endl;
}

int main(int argc, char *argv[])
{
sighandler_t oldHandler = signal(SIGINT, handler);

if ( oldHandler == SIG_ERR ) exit(1);

sleep(1);

if ( signal(SIGINT, oldHandler) == SIG_ERR ) exit(1);

sleep(10);
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: