The response process of the signal

Source: Internet
Author: User

Come on! Review what is the unreliable signal? Think for a while???

Signal execution site is the kernel to help us decorate, so if a signal is performing a behavior, at this time embarrassed to have a signal, then, the first behavior will be the second behavior is overwritten.

Solve the unreliable----> reentrant function: The first call is not finished, the second call comes, but does not error;

All system calls are reentrant, and some library functions can be re-entered.

Eg:open Read memcpy rand a lot more ...

int rand (void): Non-reentrant: Generates a pseudo-random sequence of numbers, each of which has a previous number calculated by some calculation. If I were to generate the nth value, and Rand was called by WHO, then the value of n+1 would be a difference.

reentrant function = = "int rand_r (unsigned int *seedp): Then all the random numbers are calculated by SEEDP this value.

_r Version: Reentrant function

The response process of the signal

Process:

The premise needs to understand: The kernel maintains two bitmaps for each process: mask: The status of the current signal (initial 1, signal behavior performed as 0) pending signal flag bit (initial 0, signal 1)

Procedural phenomena:

1.main Start Printing * * *

2.CTRL+C Arrival Print!

3. Continue Printing * * * * until end of program

Specific implementation steps:

1. * * *

2.CTRL+C Arrival--->pending a bit = 1

3. Wait until the interruption comes.

4. Hold the scene to the core: content: including return address----point to the-->main function of a location

5. In the ready queue awaiting dispatch, many processes are queued-----> your turn.

6. From Kernal to User:mask & pending = 1 & 1 A bit for 1 other bits 0, Signalnum = = SIGINT

7. Replace the mask = 0 pending= 0 address with the address of the signal processing function handler

8. Print! Signal handler finishes executing

9. Return to the kernel replacement address: The address of the signal processing function handler replaced with a location of the main function

mask = 1;

11. From kernal back to user wait schedule: Mask 1 & Pending 0 processing function is done.

12. Continue Printing * * * *

Ignore signal: The mask position of the signal is 0 does not stop the signal, but can prevent the signal is not responding

Mask pending

1 0//Initial---"Interrupted---" Core---"Storage site: Address---" dispatch----"kernal back to User----" Mask & pending-------"

1 1//Mask & pending = 1--------"

0 0//mask = 0 pending = 0-----"To perform the handler function------"

1 0/mask = 1 pending = 0------"Kernal back to User----mask & pending-------"

The response process of the signal

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.