希望接收SIGUSR1 信号进行处理,但是收到后无法处理,进程直接退出,不知道为什么,程序如下:
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdbool.h>
static int linphone_pid;
static bool recvpid;
void sig_handler(int ,siginfo_t*,void*);
main()
{
int send_usr1;
linphone_pid=0;
recvpid=0;
struct sigaction act;
union sigval mysigval;
pid_t pid=0;
int data=0;
sigemptyset(&act.sa_mask);
act.sa_sigaction=sig_handler;
act.sa_flags=SA_SIGINFO;
sigaction(SIGUSR1,&act,NULL);
while(1)
{
sleep(2);
printf("still alive\n");
printf("Please input the number:[808 means send the message of route reply] ");
scanf("%d",&send_usr1);
if (send_usr1==80
{
if(recvpid==1){
printf("Have receive the linphone pid\n PID is %d\n",linphone_pid);
data=send_usr1;
pid=linphone_pid;
mysigval.sival_int=data;
sigqueue(pid,SIGUSR1,mysigval);
}
else
printf("Have not receive the linphone pid!\n");
}
}
}
void sig_handler(int signum,siginfo_t *info,void *myact)
{
if (signum==SIGUSR1)
{
int recvdata;
printf("It is a SIGUSR1\n");
recvdata=info->si_int;
printf("The receive extra data is %d\n",recvdata);
linphone_pid=recvdata;
printf("Receive a linphone pid %d\n",linphone_pid);
recvpid=1; //have get the linphone pid
printf("Handler processing over!\n");
}
else
{
printf("It is not a SIGUSR1.\n");
}
} |