找回密码
 注册
查看: 974|回复: 0

求助:进程收到信号总是直接退出

[复制链接]
发表于 2006-7-30 00:49:41 | 显示全部楼层 |阅读模式
希望接收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");
          }

}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-6 19:15 , Processed in 0.029430 second(s), 16 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表