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

LINUX 进程间 信号

2010-05-09 14:32 246 查看
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <signal.h>

using namespace std;

extern char **environ;

void signal_handle(int signal_no){
cout << "sign:" <<signal_no << endl;
}

int main(int args,char *argc[]){

pid_t pid=fork();

if(pid<0){
cout << "fork error!" <<endl;
}else if(pid==0){

signal(SIGUSR1,signal_handle_kill);
int count=0;
while(count<10){
count++;
cout << "count:" <<count <<endl;
sleep(1);
}
kill(getppid(),SIGUSR1);
}else{
signal(SIGUSR1,signal_handle);
pause();
}

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