OS X sigaction错误地设置了sa_mask

OS X sigaction错误地设置了sa_mask,第1张

概述在macbook(OSX 10.9.5(13F34))上有以下简单程序: #include <stdio.h>#include <signal.h>static void nop(int unused) { }intmain(void) { struct sigaction sa, osa; sigset_t mask; sigemptyset(&sa.sa_ 在macbook(OSX 10.9.5(13F34))上有以下简单程序:

#include <stdio.h>#include <signal.h>static voID nop(int unused) { }intmain(voID) {    struct sigaction sa,osa;    sigset_t mask;    sigemptyset(&sa.sa_mask);    printf("Errno after sigempty sa_mask: %d\n",errno);    sigemptyset(&osa.sa_mask);    printf("Errno after sigempty oldsa_mask: %d\n",errno);    sa.sa_flags = 0;    sa.sa_handler = nop;    sigprocmask(0,NulL,&mask);    printf("Errno after sigprocmask mask: %d\n",errno);    printf("%d\n",sigismember(&mask,SIgalRM));    sigaction(SIgalRM,&sa,&osa);    printf("Errno after sigaction sa osa: %d\n",sigismember(&osa.sa_mask,SIgalRM));    printf("%d\n",sigismember(&sa.sa_mask,SIgalRM));    return 0;}

神秘印刷:

Errno after sigempty sa_mask: 0Errno after sigempty oldsa_mask: 0Errno after sigprocmask mask: 00Errno after sigaction sa osa: 010

我希望osa的sa_mask成员匹配sigprocmask给出的掩码.

POSIX是否指定了该字段的任何要求?在联机帮助页中唯一提到的是关于SIGKILL等不可阻塞的信号,其中该值未指定.

在linux上,这个程序打印:

Errno after sigempty sa_mask: 0Errno after sigempty oldsa_mask: 0Errno after sigprocmask mask: 00Errno after sigaction sa osa: 000

正如所料.

gcc版本是:

$gcc --versionConfigured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)Target: x86_64-apple-darw

二进制文件链接到:

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0,current version 1197.1.1)
解决方法

I would expect that the sa_mask member of osa to match mask as given by sigprocmask.

你的期望是不正确的.

这是the current (as of this writing) official POSIX documentation的链接.收藏它!

Here is what that documentation says about sa_mask:

Additional set of signals to be blocked during execution of signal-catching function.

没有理由期望osa.sa_mask匹配掩码.你的面具是当前的信号掩码.你的osa.sa_mask是一个额外的信号掩码,在调用osa.sa_handler来处理SIgalRM时应用.

在您的测试用例中,osa.sa_handler是SIG_DFL,因此osa.sa_mask的内容无关紧要.据我所知(在简短的搜索之后),POSIX没有说明osa.sa_mask应该是什么时候,就像你的测试案例一样,该过程自最近的执行官以来没有为信号设置动作.

此外,当系统调用已安装的SIgalRM处理程序时,它会自动在信号掩码中包含SIgalRM(除非您在安装处理程序时传递了SA_NODEFER或SA_resetHAND).引用上面链接的文档:

When a signal is caught by a signal-catching function installed by sigaction(),a new signal mask is calculated and installed for the duration of the signal-catching function (or until a call to either sigprocmask() or sigsuspend() is made). This mask is formed by taking the union of the current signal mask and the value of the sa_mask for the signal being delivered,and unless SA_NODEFER or SA_resetHAND is set,then including the signal being delivered.

因此,如果sa_flags为0,则sa_mask是否包含SIgalRM无关紧要.事实上linux不包含它并且OS X确实对信号的处理没有任何影响.

另请注意,对于sigprocmask的how参数传递0(而不是其中一个已定义的常量),即使set参数为null,也不清楚(对我而言)是合法的.但我发现将它改为SIG_BLOCK没有任何区别.

总结

以上是内存溢出为你收集整理的OS X sigaction错误地设置了sa_mask全部内容,希望文章能够帮你解决OS X sigaction错误地设置了sa_mask所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1216384.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存