Consistency issues with the Shell's trap

Source: Internet
Author: User

Example 1:

[Email protected] example]$ more trapping

#!/bin/sh

# scriptname:trapping

# Script to illustrate the trap command and Signals

Trap ' echo ' ctrl-c would not terminate $. "' 2

Trap ' echo ' ctrl-\ would not terminate $. "' 3

echo "Enter any string after the prompt."

echo "When is ready to exit, type \" Stop\ "."

While True

Do

Echo-n "Go ahead...>"

Read reply

If ["$reply" = Stop]

Then

Break

Fi

Done

[Email protected] example]$ sh trapping

Enter any string after the prompt.

When you were ready to exit, type "Stop".

Go ahead...> ^cctrl-c would not terminate trapping.

Note: This indicates that the 2 signal is able to be captured and processed

Go ahead...> Stop

[[email protected] example]$ trap

Trap--"' SIGTSTP

Trap--"' Sigttin

Trap--"' Sigttou

[Email protected] example]$

Example 2:

[Email protected] example]$ more trapping

#!/bin/sh

# scriptname:trapping

# Script to illustrate the trap command and Signals

Trap ' echo ' ctrl-c would not terminate $. "' 9

Trap ' echo ' ctrl-\ would not terminate $. "' 3

echo "Enter any string after the prompt."

echo "When is ready to exit, type \" Stop\ "."

While True

Do

Echo-n "Go ahead...>"

Read reply

If ["$reply" = Stop]

Then

Break

Fi

Done

[Email protected] example]$ sh trapping

Enter any string after the prompt.

When you were ready to exit, type "Stop".

Go ahead...> killed

Note : This indicates that the 9 signal cannot be captured, let alone processed.

[Email protected] example]$

The following actions are performed synchronously:

[Email protected] ~]$ Ps-ef|grep trapping

Maokx 5004 2968 0 11:18 pts/0 00:00:00 sh trapping

Maokx 5008 3248 0 11:18 pts/1 00:00:00 grep--color=auto trapping

[Email protected] ~]$ kill-9 5004

[Email protected] ~]$

Summary: This indicates that the trap also does not guarantee the consistency of the operation, but also proves that the operation in the shell does not guarantee the consistency of operation


Consistency issues with the Shell's trap

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.