#include <stdio.h>
#include <signal.h>
#include <unistd.h>

void signalHandler(int signo);

main()
{
    /* SIGINT 시그널 받으면 signalHandler 실행하도록 설정 */
    signal(SIGINT, signalHandler);
    while(1) {
       printf("Hello World\n");
       sleep(1);
    }
}

void signalHandler(int signo)  
{
//SIGINT 시그널을 받으면 이함수가 소출되고 SIGINT의 넘버를 받은 signo를 출력하고
    printf("Hi! signal %d\n", signo);  /* signo는 시그널 번호를 출력을 해준다 */
    /* SIGINT 시그널 받으면 시스템에서 기본적으로 설정한 동작을 하도록 설정
        SIG_DFL이 실행 그다음 부터는 월래 대로 키를 입력하는대로 먹는다*/

    signal(SIGINT, SIG_DFL);
}


      c 언어  |  2007. 9. 17. 09:58



sokoban's Blog is powered by Daum & Tattertools