//简单的捕捉段错误信号信号处理程序,通过signal来捕捉错误.
#include
<
stdio.h
>
#include < signal.h >
#include < stdlib.h >
void handler( int s)
{
if (s == SIGINT) printf( " now got a interrupt signal " );
if (s == SIGSEGV) printf( " now got a segmentation violation signal " );
if (s == SIGILL) printf( " now got an illegal instruction signal " );
exit( 1 );
}
int main()
{
int * p = NULL;
signal(SIGINT, handler);
signal(SIGSEGV,handler);
signal(SIGILL, handler);
* p = 0 ;
return 0 ;
}
#include < signal.h >
#include < stdlib.h >
void handler( int s)
{
if (s == SIGINT) printf( " now got a interrupt signal " );
if (s == SIGSEGV) printf( " now got a segmentation violation signal " );
if (s == SIGILL) printf( " now got an illegal instruction signal " );
exit( 1 );
}
int main()
{
int * p = NULL;
signal(SIGINT, handler);
signal(SIGSEGV,handler);
signal(SIGILL, handler);
* p = 0 ;
return 0 ;
}