act.sa_sigaction = NULL;這壹行去掉就沒問題了!
#include
#include
#include
#include
void sigusr1_handler(int signo)
{
printf("catch SIGUSR1\n");
sleep(15);
printf("back to main\n");
}
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 begin\n");
sleep(15);
printf("done\n");
return 0;
}
如果我的回答沒能幫助您,請繼續追問。轉載,僅供參考。