Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://www.gnu.org/software/libc/manual/html_node/Signal-Handling.html" rel="nofollow noreferrer">The GNU C Library Reference Manual</a> has a whole chapter explaining everything about signal handling.</p> <p>You always get the previously set signal handler (a function pointer) when you install your own handler (see manpages for <code>signal()</code> or <code>sigaction()</code>). </p> <pre><code>previous_handler = signal(SIGINT, myhandler); </code></pre> <p>The general rule is, that you can always reset to the previous handler and <code>raise()</code> the signal again. </p> <pre><code>void myhandler(int sig) { /* own stuff .. */ signal(sig, previous_handler); raise(sig); /* when it returns here .. set our signal handler again */ signal(sig, myhandler); } </code></pre> <p>There is one <strong>disadvantage</strong> of the general rule: Hardware exceptions which are mapped to signals are usually assigned to a certain instruction which caused the exception. So, when you raise a signal again, the associated instruction is not the same as originally. This can but should not harm other signal handlers.</p> <p>Another <strong>disadvantage</strong> is, that each raised signal causes a lot of processing time. To prevent excessive use of <code>raise()</code> you can use the following alternatives: </p> <ol> <li><p>In case of <code>SIG_DFL</code> the function pointer points to address <code>0</code> (which is obviously no valid address). Thus, you <strong>have to</strong> reset the handler and <code>raise()</code> the signal again. </p> <pre><code>if (previous_handler == SIG_DFL) { signal(sig, SIG_DFL); raise(sig); signal(sig, myhandler); } </code></pre></li> <li><p><code>SIG_IGN</code> has value <code>1</code> (also an invalid address). Here you can just return (do nothing). </p> <pre><code>else if (previous_handler == SIG_IGN) { return; } </code></pre></li> <li><p>Otherwise (neither <code>SIG_IGN</code> nor <code>SIG_DFL</code>) you have received a valid function pointer and you <strong>can</strong> call the handler directly, </p> <pre><code>else { previous_handler(sig); }</code></pre></li> </ol> <p>Of course, you have to consider the different APIs as well (see manpages for <code>signal()</code> and <code>sigaction()</code>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload