- 论坛徽章:
- 0
|
#include <signal.h>
typedef void Sigfunc(int);
Sigfunc *Signal( int, Sigfunc *);
void hander(int signo);
void main()
{
Signal ( SIGALRM , hander );
alarm(1);
while ( 1 )
{
pause();
/*
sleep( 30 );
*/
}
}
void hander(int signo)
{
puts ( "haha" );
alarm(1);
return;
}
Sigfunc *Signal ( int signo , Sigfunc *func )
{
struct sigaction act , oact ;
act.sa_handler = func;
sigemptyset ( &act.sa_mask );
act.sa_flags = 0;
if ( signo == SIGALRM )
{
#ifdef SA_INTERRUPT
puts("aa");
act.sa_flags |= SA_INTERRUPT;
#endif
}else {
#ifdef SA_RESTART
act.sa_flags |= SA_RESTART;
#endif
}
puts("bbb");
if ( sigaction( signo , &act , &act ) < 0 )
{
puts("aaa");
return ( SIG_ERR );
}
return ( oact.sa_handler );
}
上面的程序运行一秒后就退出了,没打印"haha". |
|