# whatis signal
# man 7 signal
NAME signal - list of available signals DESCRIPTION Linux supports both POSIX reliable signals (hereinafter "standard signals") and POSIX real-time signals. Signal Dispositions Each signal has a current disposition, which determines how the process behaves when it is delivered the signal. The entries in the "Action" column of the tables below specify the default disposi- tion for each signal, as follows: Term Default action is to terminate the process. Ign Default action is to ignore the signal. Core Default action is to terminate the process and dump core (see core(5)). Stop Default action is to stop the process. Cont Default action is to continue the process if it is currently stopped. Signal Value Action Comment ------------------------------------------------------------------------- SIGHUP 1 Term Hangup detected on controlling terminal or death of controlling process SIGINT 2 Term Interrupt from keyboard SIGQUIT 3 Core Quit from keyboard SIGILL 4 Core Illegal Instruction SIGABRT 6 Core Abort signal from abort(3) SIGFPE 8 Core Floating point exception SIGKILL 9 Term Kill signal SIGSEGV 11 Core Invalid memory reference SIGPIPE 13 Term Broken pipe: write to pipe with no readers SIGALRM 14 Term Timer signal from alarm(2) SIGTERM 15 Term Termination signal SIGUSR1 30,10,16 Term User-defined signal 1 SIGUSR2 31,12,17 Term User-defined signal 2 SIGCHLD 20,17,18 Ign Child stopped or terminated SIGCONT 19,18,25 Cont Continue if stopped SIGSTOP 17,19,23 Stop Stop process SIGTSTP 18,20,24 Stop Stop typed at tty SIGTTIN 21,21,26 Stop tty input for background process SIGTTOU 22,22,27 Stop tty output for background process |
# kill -l
시그널 함수( signal() )
# man signal
NAME signal - ANSI C signal handling SYNOPSIS #include <signal.h> typedef void (*sighandler_t)(int); sighandler_t signal(int signum, sighandler_t handler); DESCRIPTION The signal() system call installs a new signal handler for the signal with number signum. The signal handler is set to sighandler which may be a user specified function, or either SIG_IGN or SIG_DFL. Upon arrival of a signal with number signum the following happens. If the corre- sponding handler is set to SIG_IGN, then the signal is ignored. If the handler is set to SIG_DFL, then the default action associated with the signal (see signal(7)) occurs. Finally, if the handler is set to a function sighandler then first either the handler is reset to SIG_DFL or an implementation-dependent blocking of the sig- nal is performed and next sighandler is called with argument signum. |
시그널 함수를 제공하는 방법
1. 무시
> 개발자가 만든 프로세서가 있는데 한번 실행되면 끝까지 가야하도록 해야한다.
2. 원하는 동작
> 대부분의 프로그램들은 실행하면서 임시파일을 만드는데 Ctrl + C 를 누르면 중간에 끊겨서 임시파일이 지워지지 않는다.
> 2번 시그널을 받으면 지우긴 할건데 그 전에 임시파일 지우고 종료해라.
시그널 함수 사용법
함수 사용법 |
함수 사용 예 |
설명 |
signal( 시그널 번호, SIG_DFL ) |
signal(SIGINT, SIG_DFL) |
SIGINT 시그널 실행 |
signal( 시그널 번호, SIG_IGN ) |
signal(SIGQUIT, SIG_IGN) |
SIGQUIT 시그널 무시 |
signal( 시그널 번호, handler 함수) |
signal(SIGINT, handler) |
SIGINT(Ctrl +C)가 입력되면 handler()함수 실행 |
>> handler 함수는 내가 직접 만들어야 한다.
[실습] signal() 함수 사용법
# vi signal.c
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 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include<stdio.h> #include<signal.h> #include<unistd.h> /* CTRL + C function */ void sigint_handler(int signo) { printf("received %d\n", signo); signal(SIGINT, SIG_DFL); /* signal excute */ //DFL - default } /* CTRL + Z function */ void sigtstp_handler(int signo) { printf("received %d\n", signo); signal(SIGTSTP, SIG_IGN); /* signal not excute */ } /* CTRL + \ function */ void sigquit_handler(int signo) { printf("received %d\n", signo); signal(SIGQUIT, SIG_DFL); /* signal excute */ } int main(void) { if (signal(SIGINT, sigint_handler) == SIG_ERR) { printf("\ncan't catch signal\n"); } if(signal(SIGTSTP, sigtstp_handler) == SIG_ERR) { printf("\ncan't catch signal\n"); } if(signal(SIGQUIT, sigquit_handler) == SIG_ERR) { printf("\ncan't catch signal\n"); } while(1) sleep(1); return 0; } | cs |
# gcc -o signal signal.c
# ./signal
'보안과정 > 참고' 카테고리의 다른 글
변수의 메모리 배치 확인과 GDB 사용법 (0) | 2017.11.30 |
---|---|
아스키 코드표 (0) | 2017.11.29 |
ln 명령어 (0) | 2017.11.29 |
nc(netcat)명령어 사용법 (0) | 2017.11.28 |
xinetd 방식에 대하여 (0) | 2017.11.28 |