Linux Trap (SNAP) command

Source: Internet
Author: User

The Trap command is used to specify the action to be taken after the signal is received;

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. and you must specify the trap command before the part of the code that you want to protect.

Format: Trap Commands signal-list

Example: Trap "Cp-f/etc/resolv.conf.bak/etc/resolv.conf;exit" INT

..........................................

Signal (SIGINT) 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


INT is the interrupt signal (Ctrl-c,sco UNIX is the "Del" key in Linux)

The trap is the capture signal, which is associated with the provided ARG, which performs the action specified by ARG when a signal is captured.

#!/bin/bash

Trap "ECHO-E \" \nreceive int\n\ "; exit" int

While:

Do

((i++))

Done

Since it is a dead loop and will not exit, after pressing the CTRL-C key, the program will display, receive int, and return the $ status. When Arg is empty, the signal indicated later is ignored

Trap-p

The command associated with the signal can be displayed. Please correct me.


This article is from the "North Ice--q" blog, please be sure to keep this source http://beibing.blog.51cto.com/10693373/1894457

Linux Trap (SNAP) command

Related Article

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.