Topic
Shell Scripting Knowledge points: What are trap signals in Linux system scripts and how are they used?
Reference answer: "Trap signal Command description"
The trap command is used to specify the actions to be taken after a signal is received, and a common use of the trap command is to complete the cleanup work when the script is interrupted.
Historically, the shell always used numbers to represent the signal, and the new script should use the name of the signal, which was saved in the Signal.h header file included with the # include command, and the sig prefix needed to be omitted when using the signal name.
You can enter the command trap-l at the command prompt to view the signal number and its associated name.
"Trap Signal Command Usage"
The parameters of the trap command are divided into two parts, the first part is the action to be taken when the specified signal is received, and the latter part is the signal name to be processed.
· To reset the processing condition of a signal to its default value, simply set the command to-.
· to ignore a signal, set command to an empty string '
A trap command without parameters will list the current set of signals and their actions.
"Trap Important signal description"
Signal Information |
Signal Description |
HUP (1) |
Hangs, usually caused by a terminal drop or user exit |
INT (2) |
Interrupt, usually caused by pressing CTRL + C key combination |
QUIT (3) |
Exit, usually caused by pressing the ctrl+\ key combination |
ABRT (6) |
Abort, usually caused by some serious execution error |
ALRM (14) |
Alarms, typically used to process timeouts |
Term (15) |
Terminated, usually sent at system shutdown |
Note
Today is the day to accompany everyone's first __69 days __, look forward to your progress.
For questions and answers, please leave a comment in the blog comments section.
Index of the topic of the previous period
http://lidao.blog.51cto.com/3388056/1914205
This article is from the "Lee blog" blog, make sure to keep this source http://lidao.blog.51cto.com/3388056/1936555
Old boy Education daily-69th Day-shell scripting Knowledge Points: What are trap signals in Linux system scripts and how do I use them?