#include
Void (*signal(int signo, void (*func)(int)))(int);
返回值是之前的signal处理函数,错误返回SIG_ERR
1. Signo:signal的名称
2. Func:函数地址,或者是SIG_IGN(忽略Signal)或SIG_DFL(缺省行为)。原型为:void (*)(int)。不过很多UNIX的实现也会传入一些和实现相关的参数。
######################################################################
#include
#include
#include
void sig_quit(int signo)
{
printf("caught SIGQUIT\n");
signal(SIGQUIT, SIG_DFL);
return ;
}
int main(int argc, char *argv[])
{
unsigned int unslept;
signal(SIGQUIT, sig_quit);
while(1);
return 0;
}
$a.out
^\
caught SIGQUIT
^\Quit
####################################################################
#include
#include
#include
void sig_quit(int signo)
{
printf("caught SIGQUIT\n");
return ;
}
int main(int argc, char *argv[])
{
unsigned int unslept;
signal(SIGQUIT, sig_quit);
while(1);
return 0;
}
$a.out
^\caught SIGQUIT
^\caught SIGQUIT
^\caught SIGQUIT
^\caught SIGQUIT
##################################################################
#include
#include
#include
void sig_quit(int signo)
{
printf("caught SIGQUIT\n");
printf("caught SIGQUIT\n");//有无结果一样
return ;
}
int main(int argc, char *argv[])
{
unsigned int unslept;
signal(SIGQUIT, sig_quit);
unslept = sleep(20);
printf("unslept time = %u\n", unslept);
return 0;
}
$a.out
^\caught SIGQUIT
unslept time = 19
###############################################################
#include
#include
#include
int main(int argc, char *argv[])
{
unsigned int unslept;
printf("caught SIGQUIT\n");
unslept = sleep(20);
printf("unslept time = %u\n", unslept);
return 0;
}
$a.out
^\Quit
阅读(1052) | 评论(0) | 转发(0) |