Signal reentrant function

Source: Internet
Author: User

When a process captures and processes the signal, the command sequence being executed by the process is temporarily interrupted by the signal processing program. It first executes the commands in the signal processing program. If it is returned from the signal processing program (for example, the signal processing program does not call exit or longjmp), it continues to execute the normal command sequence that the process is executing when the signal is captured. However, in the signal processing program, the process cannot determine where to execute when the signal is captured.If the program is executing malloc, allocate another storage space in its heap, and insert and execute the signal processing program due to capturing the signal, and then call malloc, this may cause damage to the process, because malloc usually maintains a chain table for the storage zone it is allocated, and the process may be changing the chain table when inserting the signal processing program. For example, if a process is executing a function, such as getpwnam, that stores its results in a static storage unit, and inserts an execution signal processing program, it calls such a function, the information returned to the normal caller may be overwritten by the information returned to the signal processing program.

Most functions not listed in table 10-3 cannot be reentrant because: (a) they are known to use static data structures, (B) they call malloc or free, or (c) they are standard I/O functions.

It should be noted that even if the signal processing program calls functions listed in table 10-3, since each thread only has one errno variable, the signal processing program may modify its original value. Therefore,As a general rule, when calling the functions listed in table 10-3 in the signal processing program, it should be saved before it and restored after it.

If a non-reentrant function is called in the signal processing program, the result is unpredictable.

This blog is excerpted from advanced programming for UNIX environments (version 2) and used only for personal learning records. For more information about this book, see:Http://www.apuebook.com/.

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.