当前位置: 技术问答>linux和unix
sigaction()函数问题
来源: 互联网 发布时间:2016-11-26
本文导语: #include #include #include void usr1_handler(int signo) { printf("Catch SIGUSR1n"); sleep(5); printf("back to mainn"); } int main() { struct sigaction act; act.sa_handler = usr1_handler; act.sa_flags = 0; act.sa_sigaction = NULL; sigemptyset(&act.sa_mask); if(...
#include
#include
#include
void usr1_handler(int signo)
{
printf("Catch SIGUSR1n");
sleep(5);
printf("back to mainn");
}
int main()
{
struct sigaction act;
act.sa_handler = usr1_handler;
act.sa_flags = 0;
act.sa_sigaction = NULL;
sigemptyset(&act.sa_mask);
if(sigaction(SIGUSR1, &act, NULL) == -1){
printf("sigaction errorn");
exit(1);
}
// signal(SIGUSR1, usr1_handler);
printf("process beginn");
printf("the parent pid: %dn", getpid());
sleep(10);
printf("donen");
return 0;
}
#include
#include
void usr1_handler(int signo)
{
printf("Catch SIGUSR1n");
sleep(5);
printf("back to mainn");
}
int main()
{
struct sigaction act;
act.sa_handler = usr1_handler;
act.sa_flags = 0;
act.sa_sigaction = NULL;
sigemptyset(&act.sa_mask);
if(sigaction(SIGUSR1, &act, NULL) == -1){
printf("sigaction errorn");
exit(1);
}
// signal(SIGUSR1, usr1_handler);
printf("process beginn");
printf("the parent pid: %dn", getpid());
sleep(10);
printf("donen");
return 0;
}
|
//act.sa_sigaction = NULL;
男人(man)告訴我們,“On some architectures a union is involved: do not assign to both sa_handler and sa_sigaction.”。