【发布时间】:2011-03-01 11:37:54
【问题描述】:
我在我的代码中放置了一个简单的信号处理程序。我已经初始化了 sigevent 结构,并使用一个处理函数来捕获信号。
有人可以指出为什么代码不起作用吗?理想情况下,如果有信号,应该调用我的处理程序。但事实并非如此。
请帮帮我, 谢谢 Kingsmasher1
enter code here
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
void my_handler(int sival_int, void* sival_ptr)
{
printf("my_handler caught\n");
signal(sig,my_handler);
}
int main()
{
struct sigevent sevp;
sevp.sigev_notify=SIGEV_THREAD;
sevp.sigev_signo=SIGRTMIN;
sevp.sigev_value.sival_ptr=NULL;
sevp.sigev_notify_function=(void*)my_handler;
kill(0,SIGRTMIN); // This should invoke the signal and call the function
}
【问题讨论】:
标签: c linux unix posix signals