리눅스 시그널 - 해당되는 글 7건

#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





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

main()
{
    int count=0;

    /* SIGINT 시그널 받으면 무시하도록 설정 */
    signal(SIGINT, SIG_IGN);
    while (1) {
       printf("Hello World\n");
       sleep(1);
       if (++count == 5)   /* count가 5가 되면 */
          /* SIGINT 시그널 받으면 시스템에서 기본적으로 설정한 동작을 하도록 설정 */
          signal(SIGINT, SIG_DFL);
    }
}
5초가 지날때까지 콘트롤 제트가 먹지 않는다

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




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

main()
{
    /* SIGINT 시그널 받으면 무시하도록 설정 */
    signal(SIGINT, SIG_IGN);
    while (1) {
       printf("Hello World\n");
       sleep(1);   /* 1초 동안 정지 */
    }
}

콘트롤 -Z 해서 스탑하고 나간당. 그리고 킬-9를 입력 킬한다.


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



sokoban's Blog is powered by Daum & Tattertools