Analysis of Linux signals using

One, the linux signal

 1) SIGHUP   2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP
 6) SIGABRT  7) SIGBUS   8) SIGFPE   9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG  24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF 28) SIGWINCH    29) SIGIO   30) SIGPWR
31) SIGSYS  34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX

1, the terminal button generates a signal

Ø Ctrl + c  → 2) SIGINT(终止/中断)     "INT" ----Interrupt
Ø Ctrl + \  → 3) SIGQUIT(退出)    
Ø Ctrl + z  → 20) SIGTSTP(暂停/停止)  "T" ----Terminal 终端。

2, the hardware abnormality generates a signal

Ø 总线错误      → 7) SIGBUS
Ø 除0操作      → 8) SIGFPE (浮点数例外)    "F" -----float 浮点数。
Ø 非法访问内存  → 11) SIGSEGV (段错误)

3, List of Linux regular signals


2
(SIGINT),
3(SIGQUIT),
6(SIGABRT),
9(SIGKILL),
11(SIGSEGV),
14(SIGALRM),
17(SIGCHLD),
19(SIGSTOP),
20(SIGTSTP) signals to remember

serial number Signal corresponding event default action
1 SIGHUP When the user exits the shell, all processes started by that shell will receive this signal kill process
2 SIGINT When the user presses a key combination, the user terminal sends this signal to the running program started by the terminal kill process
3 SO MUCH This signal is generated when the user presses a key combination, and the user terminal sends some signals to the running program started by the terminal kill process
4 SEAL The CPU detects that a process has executed an illegal instruction Terminate the process and generate the core file
5 SIGTRAP This signal is generated by a breakpoint instruction or other trap instruction Terminate the process and generate the core file
6 SIGABRT This signal is generated when the abort function is called Terminate the process and generate the core file
7 SIGBUS Illegal access to memory addresses, including memory alignment errors Terminate the process and generate the core file
8 SIGFPE Emitted when a fatal arithmetic error occurs. Not only floating point arithmetic errors, but also all arithmetic errors such as overflow and division by 0 Terminate the process and generate the core file
9 SIGKILL Terminate the process unconditionally. This signal cannot be ignored, handled and blocked kill process, any process can be killed
10 SIGUSE1 User-defined signal. That is, the programmer can define and use the signal in the program kill process
11 SIGSEGV Indicates that the process made an invalid memory access (segmentation fault) Terminate the process and generate the core file
12 SIGUSR2 Another user-defined signal that the programmer can define and use in the program kill process
13 SIGPIPE Broken pipe writes data to a pipe without a read end kill process
14 SIGALRM The timer times out, the time out is set by the system call alarm kill process
15 SIGTERM Program end signal. Unlike SIGKILL, this signal can be blocked and terminated. Usually used to indicate that the program exits normally. When executing the shell command Kill, this signal is generated by default kill process
16 SIGSTKFLT Signals that appeared in early versions of Linux, Backward compatibility remains
17 SIGCHLD When the child process ends, the parent process will receive this signal ignore this signal
18 SIGCONT If the process is stopped, keep it running continue/ignore.
19 SIGSTOP Stop the execution of the process. Signals cannot be ignored, handled and blocked to terminate the process
20 SIGTSTP Stop the terminal interactive process from running. This signal is emitted when a key combination is pressed Pause the process
21 SIGTTIN Background process reading terminal console Pause the process
22 SIGTTOU This signal is similar to SIGTTIN and occurs when a background process wants to output data to the terminal Pause the process
23 SIGURG When there is urgent data on the socket, send some signals to the currently running process to report that urgent data has arrived. As network out-of-band data arrives ignore this signal
24 SIGXCPU The process execution time exceeds the CPU time allocated to the process, the system generates the signal and sends it to the process kill process
25 SIGXFSZ Exceeds the file's maximum length setting kill process
26 SIGVTALRM This signal is generated when the virtual clock times out. Similar to SIGALRM, but this signal only counts the CPU usage time of the process kill process
27 SGIPROF Similar to SIGVTALRM, it does not include the CPU time spent by the process and the execution time of system calls kill process
28 SIGWINCH Emitted when the window is resized ignore this signal
29 SIGIO This signal indicates to the process that an asynchronous IO event was issued ignore this signal
30 SIGPWR shutdown kill process
31 SIGSYS invalid system call Terminate the process and generate the core file
34~64 SIGRTMIN ~ SIGRTMAX LINUX real-time signals, they have no fixed meaning (can be customized by the user) kill process

Second, the use of the registered signal signal function

Prototype of the function:

#include <signal.h>

       typedef void (*sighandler_t)(int);

       sighandler_t signal(int signum, sighandler_t handler);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324495141&siteId=291194637