Custom Signal Handler를 만들어서 사용하는 방법에 대해서 알아본다.
시그널의 종류 Sigaction을 사용하여 Custom Signal Handler 등록하기 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
void handler ( int signo , siginfo_t * info , void * context )
{
struct sigaction oldact ;
if ( sigaction ( SIGSEGV , NULL , & oldact ) == - 1 || ( oldact . sa_flags & SA_UNSUPPORTED ) || ! ( oldact . sa_flags & SA_EXPOSE_TAGBITS ))
{
_exit ( EXIT_FAILURE );
}
_exit ( EXIT_SUCCESS );
}
int main ( void )
{
struct sigaction act = { 0 };
act . sa_flags = SA_SIGINFO | SA_UNSUPPORTED | SA_EXPOSE_TAGBITS ;
act . sa_sigaction = & handler ;
if ( sigaction ( SIGSEGV , & act , NULL ) == - 1 )
{
perror ( "sigaction" );
exit ( EXIT_FAILURE );
}
raise ( SIGSEGV );
}
async-signal-safe function을 사용해야 한다. signal-safety(7) — Linux manual page
Licensed under CC BY-SA 4.0