Common commands: How to Use the trap command to capture Signals

Source: Internet
Author: User

From http://blog.freebug.org/archives/334

 

It corresponds to three different signal response methods.
First:
Trap "" commands "" signal-list

When the script receives signals listed in the signal-list, the trap command executes the commands in double quotation marks.
Second:
Trap signal-list
Trap does not specify any command and receives the default signal operation. The default operation ends the process.

Third:
Trap "signal-list
The trap command specifies an empty command string that allows ignoring signals.

Introduction to Linux Signals
1) The sighup signal is sent at the end of the user terminal connection (normal or abnormal). Generally, when the control process of the terminal ends, it notifies all jobs in the same session, they are no longer associated with the control terminal.
2) The SIGINT program termination (Interrupt) signal is sent when you type the intr character (usually Ctrl-C)
3) sigquit is similar to SIGINT, but it is controlled by the quit character (usually Ctrl. A process generates a core file when it exits after receiving sigquit. In this sense, it is similar to a program error signal.
4) sigill executes illegal commands. This is usually because the executable file itself has an error or attempts to execute data segments. This signal may also be generated when the stack overflows.
5) sigtrap is generated by the breakpoint instruction or other trap instruction. It is used by the debugger.
6) when the SIGABRT program finds an error and calls abort.
7) sigiot is produced by Iot instructions on the PDP-11, and is the same as SIGABRT on other machines.
8) An error occurred in sigbus illegal address, including memory address alignment. eg: an integer with four characters in length, but its address is not a multiple of 4.
9) sigfpe is triggered when a fatal arithmetic operation error occurs. It includes not only floating point operation errors, but also overflow and all other arithmetic errors such as Division 0.
10) sigkill is used to immediately end program running. This signal cannot be blocked, processed, or ignored.
11) SIGUSR1 is reserved for users
12) SIGSEGV tries to access the memory not allocated to itself, or try to write data to the memory address with no write permission.
13) sigusr2 is reserved for users
14) sigpipe broken pipe
15) The sigalrm clock timing signal is calculated based on the actual time or clock time. The alarm function uses this signal.
16) The sigterm program terminate signal. Unlike sigkill, this signal can be blocked and processed. It is usually used to require the program to exit normally. The shell command kill generates this signal by default.
17) when the sigchld sub-process ends, the parent process will receive this signal.
18) sigcont allows a stopped process to continue execution. this signal cannot be blocked. A handler can be used to allow a program to complete a specific job when it changes from the stopped state to the continue execution. for example, re-display the prompt
19) sigstop stops the execution of the process. Note the difference between it and terminate and interrupt: the process has not ended, but is paused. This signal cannot be blocked, processed, or ignored.
20) sigtstp stops the process, but the signal can be processed and ignored. This signal is sent when you type the susp character (usually Ctrl-Z ).
21) sigttin when the background job needs to read data from the user terminal, all the processes in the job will receive the sigttin signal. If there is a shortage of time, these processes will stop running.
22) sigttou is similar to sigttin, but it is received when the write terminal (or modify the terminal mode.
23) sigurg generates emergency data or out-of-band data when it reaches the socket.
24) The sigxcpu exceeds the CPU time limit. This limit can be read/changed by getrlimit/setrlimit.
25) sigxfsz exceeds the file size resource limit.
26) sigvtalrm virtual clock signal. Similar to sigalrm, the CPU time occupied by the process is calculated.
27) sigprof is similar to sigalrm/sigvtalrm, but includes the CPU time used by the process and the system call time.
28) it is issued when the sigwinch window size is changed.
29) The sigio file descriptor is ready for input/output operations.
30) sigpwr power failure Source: exam-Linux Certification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.