菜鸟教程小白 发表于 2022-12-13 10:17:14

ios - 如何在 iOS 上获取当前信号处理程序?


                                            <p><p>您好,我需要获取使用此方法设置的当前信号处理程序:</p>

<pre><code>signal(SIGSEGV, handler);
</code></pre>

<p>怎么做?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>不幸的是,C 标准没有预见到读取处理程序的当前值。</p>
<p>但幸运的是<a href="https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man3/signal.3.html" rel="noreferrer noopener nofollow">signal()</a>更改处理程序时返回先前的值。因此,您可以这样做有轻微的风险:</p>
<pre><code>typedef void (*sighandler_t)(int);/* for convenience */

sighandler_t current_handler;
current_handler = signal(SIGSEGV, SIG_IGN);/* (1) */
signal (SIGSERV, current_handler); /* (2) */
</code></pre>
<p>有两个风险:</p>
<ul>
<li>可能有一个(非常不可能的)错误导致 <code>signal()</code> 返回 <code>SIG_ERR</code>。然后,您将永远失去当前的处理程序!根据上面的 iOS 手册页,根据您感兴趣的信号值,不满足错误的条件。</li>
<li>如果 <code>SIGSEGV</code> 将在 (1) 和 (2) 之间引发,您将不​​会拦截它。但是,查看这两个语句,它们不太可能触发分段违规 (SIGSEGV)</li>
</ul></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 iOS 上获取当前信号处理程序?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/28529257/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/28529257/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 iOS 上获取当前信号处理程序?