1

我在 Solaris 平台上有一些遗留代码,我想将其移植到 Linux,但我在 Linux 上遇到了一些编译错误。在 Solaris 上,我有以下代码片段:

#include <signal.h>
...
void f() {
    struct sigaction a;
    sigaction(sig,0,&a);
    std::cout << (void *) a.sa_handler
        << ", " << (void *) a.sa_sigaction
        << ", " << a.sa_mask.__sigbits[0]
        << ", " << a.sa_mask.__sigbits[1]
        << ", " << a.sa_mask.__sigbits[2]
        << ", " << a.sa_mask.__sigbits[3]
        << ", " << (void *) a.sa_flags
        << std::endl;
}

当我尝试使用 gcc 4.9.2 在 Linux 上编译时(在 Solaris 上编译正常),我收到以下编译错误:

error: struct __sigset_t has no member named __sigbits
     << ", " << a.sa_mask.__sigbits[0]

... 同样对于__sigbits[1], __sigbits[2],__sigbits[3]也是如此。

Linux中是否有任何等价物?

4

1 回答 1

1

执行此操作的 POSIX 兼容方法是使用该sigismember函数。

int i;
for (i=0; i<32; i++) {
    printf("signal %d masked: %s\n", i, sigismember(&a.sa_mask, i) ? "yes", "no");
}
于 2017-04-11T12:42:49.547 回答