본문 바로가기
Linux/Shell

man signal (mac os, 파파고 번역)

by Sondho 2021. 2. 6.
NAME sigal - 단순화된 소프트웨어 신호 설비
LIBRARY 표준 C 라이브러리 (libc, -lc)
SYNOPSIS #include <signal.h>

void (*signal(int sig, void (*func)(int)))(int); 

or in the equivalent but easier to read typedef'd version: 

typedef void (*sig_t) (int); 

sig_t 

signal(int sig, sig_t func); 
DESCRIPTION 이 signal() 설비는 보다 일반적인 sigaction(2) 설비에 대한 단순화된 인터페이스이다. 

     신호는 도메인 외부에서 온 프로세스를 조작할 수 있을 뿐만 아니라 프로세스가 자체 또는 자신(자녀)의 복사본을 조작할 수 있도록 합니다.  두 가지 일반적인 유형의 신호가 있습니다. 즉, 프로세스가 종료되는 신호와 종료되지 않는 신호입니다.  프로그램의 종료를 유발하는 신호는 복구할 수 없는 오류로 인해 발생하거나 단말기의 사용자가 'interrupt' 문자를 입력함으로써 발생할 수 있다.  
     신호는 백그라운드에서 제어 단자에 액세스하려고 하기 때문에 프로세스가 중지될 때 사용됩니다(tty(4) 참조).  신호는 선택적으로 프로세스가 중지된 후 재개되거나 하위 프로세스의 상태가 변경되거나 제어 터미널에서 입력이 준비될 때 생성됩니다.  대부분의 신호는 아무런 조치도 취하지 않을 경우 프로세스를 종료하게 되며, 일부 신호는 프로세스를 수신하는 프로세스를 중지하게 하거나 프로세스가 달리 요청하지 않을 경우 간단히 폐기됩니다.  SIGKILL 및 SIGSTOP 신호를 제외하고 signal() 기능은 신호를 잡거나 무시하거나 인터럽트를 생성할 수 있도록 합니다.  이러한 신호는 <signal.h>:


     sig 인수는 수신한 신호를 지정합니다. func procedure를 통해 사용자는 신호를 수신한 후 작업을 선택할 수 있습니다. 위에 나열된 것처럼 신호의 기본 동작을 설정하려면 func가 SIG_DFL이어야 합니다.
SIG_DFL은 기본 동작을 재설정합니다. 신호를 무시하려면 func가 SIG_IGN이어야 합니다. 이로 인해 신호의 후속 인스턴스가 무시되고 보류 중인 인스턴스가 폐기됩니다. SIG_IGN을 사용하지 않으면 신호가 자동으로 차단되고 func가 호출됩니다.


     기능이 돌아오면 처리한 신호가 차단 해제되고 신호가 발생했을 때 중단된 부분부터 프로세스가 계속됩니다. 이전 신호 시설과 달리 핸들러 func()는 신호가 전달된 후에도 설치된 상태로 유지됩니다.

     일부 시스템 호출의 경우, 호출이 실행되는 동안 신호가 잡히고 통화가 조기에 종료되면 통화가 자동으로 다시 시작됩니다. 신호(3)와 함께 설치된 모든 핸들러에는 SA_RESTART 플래그가 설정되어 다시 시작할 수 있는 시스템 호출이 신호를 수신하면 반환되지 않습니다. 영향을 받는 시스템 호출에는 통신 채널이나 저속 디바이스에서 그리고 ioctl(2) 또는 wait(2)동안 read(2), write(2), send to (2), recvfrom(2), sendmsg(2) 및 recvmsg(2)가 포함됩니다. 그러나 이미 커밋된 호출은 다시 시작되지 않고 부분적인 성공(예: 짧은 읽기 수)을 반환합니다. 이러한 의미론은 sig interrupt(3)로 변경될 수 있다.

     신호 처리기가 설치된 프로세스가 포크를 만들면 하위 프로세스는 신호를 상속합니다. 잡힌 모든 신호는 execve(2) 함수에 대한 호출에 의해 기본 작업으로 재설정될 수 있으며, 무시된 신호는 무시된 상태로 유지됩니다.

     프로세스가 SIGCHLD 신호에 대한 작업으로 SIG_IGN을 명시적으로 지정하는 경우, 시스템은 호출 프로세스의 하위 항목이 종료될 때 좀비 프로세스를 생성하지 않습니다. 따라서 시스템이 하위 프로세스의 종료 상태를 무시합니다. 이후 호출 프로세스가 wait(2) 또는 equivalent 호출을 할 경우 호출 프로세스의 모든 하위 프로세스가 종료될 때까지 차단한 다음 errno가 ECHILD로 설정된 -1 값을 반환합니다.

     신호 처리기에서 사용하기에 안전한 것으로 간주되는 기능 목록은 sigaction(2)을 참조하십시오.
RETURN VALUES 이전 작업은 호출에 성공하면 반환됩니다. 그렇지 않으면 SIG_ERR이 반환되고 글로벌 변수 errno가 오류를 나타내도록 설정됩니다.
ERRORS 다음 중 하나가 발생할 경우 signal() 기능이 작동하지 않고 아무 작업도 수행되지 않습니다.

[EINVAL] 시그 인수가 올바른 신호 번호가 아닙니다.

[EINVAL] SIGKILL 또는 SIGSTOP에 대한 처리기를 무시하거나 제공하려고 합니다.
SEE ALSO kill(1), kill(2), ptrace(2), sigaction(2), sigaltstack(2), sigprocmask(2), sigsuspend(2), wait(2), fpsetmask(3), setjmp(3), siginterrupt(3), tty(4) 
HISTORY 신호 설비는 4.0BSD에 나타났다. FreeBSD 5.0에는 SIGCHLD를 무시해 좀비 아동이 생기지 않도록 하는 옵션이 등장했다.

#include <signal.h>

No Name Default Action Description
1 SIGHUP 프로세스 종료 *행업 (Hang-up)
2 SIGINT 프로세스 종료 Ctrl + c를 눌렀을 때 보내는 신호

터미널 인터럽트 신호
3 SIGQUIT 코어 이미지 생성 Ctrl + \를 눌렀을 때 보내는 신호
터미널 종료 신호
4 SIGILL 코어 이미지 생성
유효하지 않은 명령

쓸모없거나 특권이 부여된 명령어를 실행하려 했다는 의미

오직 유용한 명령어만이 발생된 C 컴파일러에서, SIGILL은 전형적으로 실행 가능 파일이 훼손되었거나, 당신이 데이터를 실행하려 시도했다는 것을 지적
5 SIGTRAP 코어 이미지 생성 트레이스/브레이크포인트 트랩

디버거들이 주로 사용하는 신호
6 SIGABRT 코어 이미지 생성 프로세스 중단 신호
7 SIGEMT 코어 이미지 생성 Emt 명령 실행시 사용되는 신호
emulate 명령이 실행됨
8 SIGFPE 코어 이미지 생성 오류가 있는 산술 조작
9 SIGKILL 프로세스 종료 강제 종료 (신호를 잡거나 무시할 수 없음)
10 SIGBUS 코어 이미지 생성 유용하지 않은 포인터가 비참조되었을 때 발생

정의되지 않은 메모리 오브젝트의 일부분에 접근
11 SIGSEGV 코어 이미지 생성 잘못된 메모리 참조
12 SIGSYS 코어 이미지 생성 불량 시스템 호출

시스템 호출을 할 때 잘못된 인수를 사용하면 발생하는 신호
13 SIGPIPE 프로세스 종료 파이프에서 사용하는 시그널로 아무도 읽지 않는 파이프에 데이터를 출력할 때 발생하는 신호
14 SIGALRM 프로세스 종료 알람 클럭
15 SIGTERM 프로세스 종료 종료 신호
16 SIGURG 폐기 신호 높은 대역의 데이터를 소켓에서 이용 가능
소켓에 도착한 데이터가 "긴급"하거나 범위를 벗어 났을 때 보내어짐
17 SIGSTOP 프로세스 중단 실행 정지 (신호를 잡거나 무시할 수 없음)

SIGCONT로 재실행시킬 수 있음
18 SIGTSTP 프로세스 중단 Ctrl + z를 입력했을 때 보내는 신호

실행 정지 후 다시 실행을 계속하기 위해 대기시키는 신호

SIGCONT로 역시 다시 실행시킬 수 있음
19 SIGCONT 폐기 신호 Continue의 약자로 STOP 시그널에 의해 정지된 프로세스를 다시 실행시킬 때 사용
20 SIGCHLD 폐기 신호 자식 프로세스가 stop 되거나 종료되었을 때 부모에게 전달되는 신호
자식 프로세스 종료, 중단, 계속
21 SIGTTIN 프로세스 중단 백그라운드 프로세스 읽기 시도
22 SIGTTOU 프로세스 중단 백그라운드 프로세스 쓰기 시도
23 SIGIO 폐기 신호 파일기술자가 입력 또는 출력을 수행할 준비가 되어있을 때 보내어진다. 
(참고 fcntl(2))
24 SIGXCPU 프로세스 종료 CPU 시간 제한 초과 (참고 setrlimit(2))
25 SIGXFSZ 프로세스 종료 파일 크기 제한 초과 (참고 setrlimit(2))
26 SIGVTALRM 프로세스 종료 가상 타이머 시간 초과 (참고 setitimer(2))
27 SIGPROF 프로세스 종료 프로파일링 타이머 시간 초과 (참고 setitimer(2))
28 SIGWINCH 폐기 신호 Window size change
29 SIGINFO 폐기 신호  Ctrl + t를 눌렀을 때 보내는 신호

키보드에서 상태 요청
30 SIGUSR1 프로세스 종료 사용자 정의 신호 1
31 SIGUSR2 프로세스 종료 사용자 정의 신호 2

*행업 (Hang-up) : 프로그램을 수행하는 도중에 프로그램 오류가 발생하더라도 전체 시스템이 중단되는 현상을 예방하는 작업

 


NAME signal -- simplified software signal facilities 
LIBRARY Standard C Library (libc, -lc)
SYNOPSIS #include <signal.h>

void (*signal(int sig, void (*func)(int)))(int); 

or in the equivalent but easier to read typedef'd version: 

typedef void (*sig_t) (int); 

sig_t 

signal(int sig, sig_t func); 
DESCRIPTION This signal() facility is a simplified interface to the more general sigaction(2) facility.

     Signals allow the manipulation of a process from outside its domain, as well as allowing the process to manipulate itself or copies of itself (children).  There are two general types of signals: those that cause termination of a process and those that do not.  Signals which cause termination of a program might result from an irrecoverable error or might be the result of a user at a terminal typing the `interrupt' character. 
     Signals are used when a process is stopped because it wishes to access its control terminal while in the background (see tty(4)).  Signals are optionally generated when a process resumes after being stopped, when the status of child processes changes, or when input is ready at the control terminal.  Most signals result in the termination of the process receiving them, if no action is taken; some signals instead cause the process receiving them to be stopped, or are simply discarded if the process has not requested otherwise.  Except for the SIGKILL and SIGSTOP signals, the signal() function allows for a signal to be caught, to be ignored, or to generate an interrupt.  These signals are defined in the file <signal.h>:


     The sig argument specifies which signal was received.  The func procedure allows a user to choose the action upon receipt of a signal.  To set the default action of the signal to occur as listed above, func should be SIG_DFL.  A SIG_DFL resets the default action.  To ignore the signal, func should be SIG_IGN.  This will cause subsequent instances of the signal to be ignored and pending instances to be discarded.  If SIG_IGN is not used, further occurrences of the signal are automatically blocked and func is called. 

     The handled signal is unblocked when the function returns and the process continues from where it left off when the signal occurred.  Unlike previous signal facilities, the handler func() remains installed after a signal has been delivered. 

     For some system calls, if a signal is caught while the call is executing and the call is prematurely terminated, the call is automatically restarted.  Any handler installed with signal(3) will have the SA_RESTART flag set, meaning that any restartable system call will not return on receipt of a signal.  The affected system calls include read(2), write(2), sendto(2), recvfrom(2), sendmsg(2), and recvmsg(2) on a communications channel or a low speed device and during a ioctl(2) or wait(2). However, calls that have already committed are not restarted, but instead return a partial success (for example, a short read count).  These semantics could be changed with siginterrupt(3). 

     When a process which has installed signal handlers forks, the child process inherits the signals.  All caught signals may be reset to their default action by a call to the execve(2) function; ignored signals remain ignored. 

     If a process explicitly specifies SIG_IGN as the action for the signal SIGCHLD, the system will not create zombie processes when children of the calling process exit.  As a consequence, the system will discard the exit status from the child processes.  If the calling process subsequently issues a call to wait(2) or equivalent, it will block until all of the calling process's children terminate, and then return a value of -1 with errno set to ECHILD. 

See sigaction(2) for a list of functions that are considered safe for use in signal handlers. 

RETURN VALUES The previous action is returned on a successful call.  Otherwise, SIG_ERR is returned and the global variable errno is set to indicate the error. 
ERRORS The signal() function will fail and no action will take place if one of the following occur: 

     [EINVAL]           The sig argument is not a valid signal number. 

     [EINVAL]           An attempt is made to ignore or supply a handler for SIGKILL or SIGSTOP. 
SEE ALSO kill(1), kill(2), ptrace(2), sigaction(2), sigaltstack(2), sigprocmask(2), sigsuspend(2), wait(2), fpsetmask(3), setjmp(3), siginterrupt(3), tty(4) 
HISTORY The signal facility appeared in 4.0BSD.  The option to avoid the creation of child zombies through ignoring SIGCHLD appeared in FreeBSD 5.0. 

 

#include <signal.h>

No Name Default Action Description
1 SIGHUP terminate process terminal line hangup
2 SIGINT terminate process interrupt program
3 SIGQUIT create core image quit program
4 SIGILL create core image illegal instruction
5 SIGTRAP create core image trace trap
6 SIGABRT create core image abort program (formerly SIGIOT)
7 SIGEMT create core image emulate instruction executed
8 SIGFPE create core image floating-point exception
9 SIGKILL terminate process kill program
10 SIGBUS create core image bus error
11 SIGSEGV create core image segmentation violation
12 SIGSYS create core image non-existent system call invoked
13 SIGPIPE terminate process write on a pipe with no reader
14 SIGALRM terminate process real-time timer expired
15 SIGTERM terminate process software termination signal
16 SIGURG discard signal urgent condition present on socket
17 SIGSTOP stop process stop (cannot be caught or ignored)
18 SIGTSTP stop process stop signal generated from keyboard
19 SIGCONT discard signal continue after stop
20 SIGCHLD discard signal chil status has changed
21 SIGTTIN stop process background read attempted from control terminal
22 SIGTTOU stop process bakground write attempted to control terminal
23 SIGIO discard signal I/O is possible on a descriptor (see fcntl(2))
24 SIGXCPU terminate process cpu time limit exceeded (see setrlimit(2))
25 SIGXFSZ terminate process fil size limit exceeded (see setrlimit(2))
26 SIGVTALRM terminate process virtual time alarm (see setitimer(2))
27 SIGPROF terminate process profiling timer alarm (see setitimer(2))
28 SIGWINCH discard signal Window size change
29 SIGINFO discard signal status request from keyboard
30 SIGUSR1 terminate process User defined signal 1
31 SIGUSR2 terminate process User defined signal 2

참고

 

유닉스 신호 - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 신호는 유닉스, 유닉스 계열, POSIX 호환 운영 체제에 쓰이는 제한된 형태의 프로세스 간 통신이다. 신호는 프로세스나 동일 프로세스 내의 특정 스레드로 전달

ko.wikipedia.org

 

 

Unix or Linux 별 프로그램 에러들..

. 프로그램 에러 시그널들 (SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGABRT) - 매우 중요 ★★★★★ 다음의 시그널들은 심각한 프로그램의 에러가 운영체제나 컴퓨터 자체에 의해 검출되었을 때 발생 된다. 일

ssambback.tistory.com

 

[ C ]signal.h 속에 정의된 시그널 종류와 설명(SIGHUP, SIGINT 등등....)

시그널 종류 설명 SIGHUP Hangup을 위한 시그널로 터미널과 시스템 사이에 통신 접속이 끊어졌을 때...

blog.naver.com

 

[리눅스 / 유닉스 ] 시그널이란? 시그널(SIGNAL) 종류, 상황, 유사 시그널 차이점

[리눅스 유닉스 완전 정복 목차] 안녕하세요~ 오늘은 시그널 SIGNAL 에 대한 간략 포스팅을 진행하고자 합니다! 트와이스의 곡 시그널이 유행(?)하면서 시그널이 신호를 의미한다는건 다들 알고 계

jhnyang.tistory.com

 

'Linux > Shell' 카테고리의 다른 글

[macOS] sed -i 에러  (0) 2021.02.24
tmux - alias, sh를 이용하여 편리하게 사용하기  (0) 2021.01.22
맥 os - SSH환경에서 화면 분할하기 (tmux)  (0) 2021.01.22
cut 명령어 옵션  (0) 2020.11.20
tr 명령어 옵션  (0) 2020.11.20

댓글