Bash Signal Processing

Source: Internet
Author: User

Bash processing signal

Send Signal

Kill

Format: kill[-s Sigspec |-n signum |-sigspec] [PID | jobspec] ...

You can send a process with a process number of PID, or you can send a process with the job number Jobspec

Sigspec can be either a signal number or a signal name, and the signal name can be no sig

The KILL command sends the SIGTERM signal by default, and the process that receives the sigterm signal ends the run

Terminal, CTRL + C sends int signal to foreground process, process exits, exit status is 130, add 128 for signal number


Processing signal

Establishing a signal callback function

Trapcmd signal1 signal2 Signal3 ...

CMD can be a sequence of commands or a function's name, or it can be empty, which will perform the default behavior


Signals of interest to shell script programming

Signal

Corresponding ID

Behavior

Meaning

SIGHUP

1

Term

hangupdetected on controlling terminal

SIGINT

2

Term

Interruptfrom keyboard

Sigquit

3

Core

Quitfrom keyboard

SIGKILL

9

Term

Killsignal

Sigalrm

14

Term

Timersignal

SIGTERM

15

Term

Terminationsignal


The shell script has a false signal 0, which is generated at exit and can be used to define a function for this signal to perform certain actions at the end of the script


Define the operation for the same signal multiple times, whichever is the last


Ignore signal

Use an empty string or colon in the trap to line.

Trap ' 2//Note the existence of quotation marks


Set timer

In fact, set up a daemon in the background to send sigalarm signals to the process after a certain event of sleep.

Way: Sleep$time && kill-s $$ &

This command generates a sleep process from the bash subprocess after the bash subprocess.

Notice the sequence of killing process when unregistering the timer, kill the parent process rashly, can't find the child process OH


This article is from the "No Front" blog, please be sure to keep this source http://qianyang.blog.51cto.com/7130735/1620558

Bash Signal Processing

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.