티스토리 뷰

// sigaction() 함수 사용 예제 프로그램
 
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>

static void sigint_handler(int signo) ;
static void sigquit_handler(int signo) ;

int main(void)
{
    struct sigaction act_int, act_quit ;

    act_int.sa_handler = sigint_handler ;
    sigemptyset(&act_int.sa_mask) ;
    sigaddset(&act_int.sa_mask, SIGQUIT) ;
    act_int.sa_flags = 0;

    if ( sigaction(SIGINT, &act_int, NULL) < 0 )
    {
        printf("sigaction() error\n") ;
        exit(-1) ;
    }

    act_quit.sa_handler = sigquit_handler ;
    sigemptyset(&act_quit.sa_mask) ;
    sigaddset(&act_quit.sa_mask, SIGINT) ;
    act_int.sa_flags = 0 ;

    if ( sigaction(SIGQUIT, &act_quit, NULL ) < 0 )
    {
        printf("sigaction() error\n") ;
        exit(-1) ;
    }

    pause() ;
}

static void sigint_handler(int signo)
{
    printf("Signal handler for SIGINT : %d\n", signo) ;
    printf("SIGQUIT signal is blocked : %d\n", signo) ;
    printf("sleep 10 sec\n") ;
    sleep(10) ;
    printf("Signal handler for SIGINT ended\n") ;
}

static void sigquit_handler(int signo)
{
    printf("Signal handler for SIGQUIT : %d\n", signo) ;
    printf("SIGINT signal is blocked : %d\n", signo) ;
    printf("sleep 10 sec\n") ;
    sleep(10) ;
    printf("Signal handler for SIGQUIT ended\n") ;
}






댓글
댓글쓰기 폼
공지사항
Total
3,675,939
Today
20
Yesterday
402
«   2022/08   »
  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 31      
글 보관함