当前位置: 技术问答>linux和unix
发送信号为什么出现User defined signal 1
来源: 互联网 发布时间:2017-02-20
本文导语: 我发信号的时候怎么会出现:User defined signal 1,请大家指教下,谢谢了 #include #include #include #include void sigusr1_handler(int signo) { printf("catch SIGUSR1n"); sleep(15); printf("back to mainn"); } int main(void) { st...
我发信号的时候怎么会出现:User defined signal 1,请大家指教下,谢谢了
#include
#include
#include
#include
void sigusr1_handler(int signo)
{
printf("catch SIGUSR1n");
sleep(15);
printf("back to mainn");
}
int main(void)
{
struct sigaction act;
act.sa_handler = sigusr1_handler;
act.sa_flags = SA_NODEFER;
act.sa_sigaction = NULL;
sigemptyset(&act.sa_mask);
if(sigaction(SIGUSR1, &act, NULL) == -1)
{
perror("fail to set handler for SIGUSR1");
exit(1);
}
printf("process beginn");
sleep(15);
printf("donen");
return 0;
}
#include
#include
#include
#include
void sigusr1_handler(int signo)
{
printf("catch SIGUSR1n");
sleep(15);
printf("back to mainn");
}
int main(void)
{
struct sigaction act;
act.sa_handler = sigusr1_handler;
act.sa_flags = SA_NODEFER;
act.sa_sigaction = NULL;
sigemptyset(&act.sa_mask);
if(sigaction(SIGUSR1, &act, NULL) == -1)
{
perror("fail to set handler for SIGUSR1");
exit(1);
}
printf("process beginn");
sleep(15);
printf("donen");
return 0;
}
|
act.sa_sigaction = NULL;这一行去掉就没问题了!
#include
#include
#include
#include
void sigusr1_handler(int signo)
{
printf("catch SIGUSR1n");
sleep(15);
printf("back to mainn");
}
int main(void)
{
struct sigaction act;
act.sa_handler = sigusr1_handler;
act.sa_flags = SA_NODEFER;
sigemptyset(&act.sa_mask);
if(sigaction(SIGUSR1, &act, NULL) == -1)
{
perror("fail to set handler for SIGUSR1");
exit(1);
}
printf("process beginn");
sleep(15);
printf("donen");
return 0;
}
#include
#include
#include
#include
void sigusr1_handler(int signo)
{
printf("catch SIGUSR1n");
sleep(15);
printf("back to mainn");
}
int main(void)
{
struct sigaction act;
act.sa_handler = sigusr1_handler;
act.sa_flags = SA_NODEFER;
sigemptyset(&act.sa_mask);
if(sigaction(SIGUSR1, &act, NULL) == -1)
{
perror("fail to set handler for SIGUSR1");
exit(1);
}
printf("process beginn");
sleep(15);
printf("donen");
return 0;
}