|
|
我在FC3下写了一个信号处理函数,如下
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
static void rthandler(int signo,siginfo_t *info,void *context)
{
int saveerr;
saveerr=errno;
printf("I have catch a ctl C\n");
sleep(5);
printf("I have sleep 5 seconds \n");
errno=saveerr;
}
int main()
{
struct sigaction act;
act.sa_sigaction=rthandler;
act.sa_flags=SA_SIGINFO;
fprintf(stderr,"I am process %ld\n",(long)getpid());
if((sigemptyset(&act.sa_mask)==-1)||
sigaction(SIGINT,&act,NULL)==-1)
{
return -1;
}
for(;;);
return 1;
}
并在另外一个进程用sigqueue向上面的进程传递信号SIGINT
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int pid;
int signo;
int sval;
union sigval value;
if(argc!=4)
{
fprintf(stderr,"Usage: %s pid signal value\n",argv[0]);
return 1;
}
pid=atoi(argv[1]);
signo=atoi(argv[2]);
sval=atoi(argv[3]);
fprintf(stderr,"Sending signal %d with value %d to process %d\n",
signo,sval,pid);
value.sival_int=sval;
if(sigqueue(pid,signo,value)==-1)
{
perror("Failed to send the signal");
return 1;
}
return 0;
}
编译链接生成sendbyqueue可执行文件
但是,当我使用./sendbyqueue 5622(接收进程的进程号) 2(SIGINT) 0(想要传递的值)时候出现问题了
我的原意是希望在接收进程5622的信号处理过程中,对它的多次信号发送会被排队,但是事实上,如果我在信号处理过程中,发送3次./sendbyqueue 5622(接收进程的进程号) 2(SIGINT) 0 除了第一次在阻塞之后被传递了,其他的信号好像都被忽略了啊
这个和sigqueque的排队机理不符合啊,小弟跪求高手予以解答... |
|