当前位置: 技术问答>linux和unix
关于进程间发送信号问题
来源: 互联网 发布时间:2016-11-18
本文导语: 代码如下: #include #include #include #include #include void handler(int signo) { switch(signo){ case SIGUSR1: printf("parent: catch sigusr1n"); break; case SIGUSR2: printf("child:catch sigusr2n"); break; ...
代码如下:
#include
#include
#include
#include
#include
void handler(int signo)
{
switch(signo){
case SIGUSR1:
printf("parent: catch sigusr1n");
break;
case SIGUSR2:
printf("child:catch sigusr2n");
break;
default:
printf("should not be heren");
break;
}
return;
}
int main()
{
pid_t ppid,cpid;
if(signal(SIGUSR1,handler)==SIG_ERR){
perror("can't set handler for SIGUSR1n");
exit(1);
}
if(signal(SIGUSR2,handler)==SIG_ERR){
perror("can't set handler for SIGUSR2n");
exit(1);
}
ppid=getpid();
if((cpid=fork())
#include
#include
#include
#include
#include
void handler(int signo)
{
switch(signo){
case SIGUSR1:
printf("parent: catch sigusr1n");
break;
case SIGUSR2:
printf("child:catch sigusr2n");
break;
default:
printf("should not be heren");
break;
}
return;
}
int main()
{
pid_t ppid,cpid;
if(signal(SIGUSR1,handler)==SIG_ERR){
perror("can't set handler for SIGUSR1n");
exit(1);
}
if(signal(SIGUSR2,handler)==SIG_ERR){
perror("can't set handler for SIGUSR2n");
exit(1);
}
ppid=getpid();
if((cpid=fork())