https://www.cnblogs.com/Carrie-0173/p/6394533.html
The impact on the process of implementation of signal processing
</h1>
<div class="clear"></div>
<div class="postBody">
When you want to deal with signal acquisition time, we can set for a signal from the signal processing function is defined , the process of the signal processing function being performed will have what effect?
First, the process of implementation of intervention:
1. When a signal is captured, the process is executing user mode program instructions (i.e., users themselves to write code or library program code ):
In this case, the code being executed process will be suspended, and instead to perform signal processing functions. As long as the signal handler does not exit () to terminate the current process or use longjmp to jump to another place, then when the signal processing function execution is completed, the process will continue to execute from start signal was interrupted at.
2. When a signal is captured, the process is executing kernel mode code ( system calls - kernel code):
At this point, unless the system call ends , or by calling the sleep primitives sleep time (and non-fast I / O short sleep) let the CPU, to perform the signal processing function is available, otherwise the signal handler can not be interrupted at the time of the implementation process .
Second, the problems caused easily
When the time code signal processing functions to interrupt the process of execution, carried out other operations, which can easily lead to the code re-entry problems, especially great for those algorithms rely on global or static data structures operational impact.
such as:
char * strtok (char * string, char * token) function, according to a given token decomposed symbol, separated from a given word string STRING. Returns a pointer to the first character of the word pointer.
When the first argument is NULL, strtok function will execute the function once the end position (the first word to be separated tail) on a continuing search for the next word.
This feature is the use of static variables according to the internal strtok function records the last end position.
If strtok function when performing the first argument is NULL signal processing function is aborted, and the signal handler is also used strtok function, then when the process returns to the strtok function is interrupted before the execution, there will be mistakes, because dependent global variables are changed.
Code signal processing functions to bring the issue of re-entry, in debugging is in difficulty , because the signal arrival time there is a certain randomness of (poor control), it is wrong to reproduce very difficult . Therefore, we in the programming, try not to overly complex functions realized by signaling mechanism.
<div id="blog_post_info">
<div class="clear"></div>
<div id="post_next_prev">
<a href="https://www.cnblogs.com/Carrie-0173/p/6365105.html" class="p_n_p_prefix">« </a> 上一篇: <a href="https://www.cnblogs.com/Carrie-0173/p/6365105.html" title="发布于 2017-02-04 15:23">堆栈的三种实现方式</a>
<br>
<a href="https://www.cnblogs.com/Carrie-0173/p/6395398.html" class="p_n_p_prefix">» </a> 下一篇: <a href="https://www.cnblogs.com/Carrie-0173/p/6395398.html" title="发布于 2017-02-13 21:10">函数模板与类模板</a>
[Recommended] cloud benefits the developer, Tencent cloud 1 nuclear 4G cloud servers from 11 yuan / month
[Recommended] new year festival, Baidu cloud intelligent cloud 1 nuclear 1G server 84 yuan / year