c - 结构 sigaction 不完整错误

标签 c linux signals

虽然包括<signal.h>我收到一条错误消息说 struct sigaction是一个不完整的类型。

我不知道如何处理它。

请帮忙

#include <signal.h>
struct sigaction act;

int main(int argc, char** argv)
{
    int depth;

    /* validate arguments number*/
    if(argc < 2)
    {
        printf("fatal error: please use arguments <MaxChild> <MaxDepth>\n");
        exit(1);
    }

    /* register the realtime signal handler for sigchld*/

/*173*/
    memset(&act,0,sizeof(act));
    act.sa_handler = sigproc;
    sigaction(SIGCHLD,  /* signal number whose action will be changed */
             &act,      /* new action to do when SIGCHLD arrives*/
             NULL);     /* old action - not stored */


    srand(time(NULL));
    depth = rand() % atoi(argv[2]); /* [0 maxDepth]*/

    RecursiveFunc(atoi(argv[1]), depth);

    return 0;
}

错误信息:

proc.c: In function ‘main’:
proc.c:173:22: error: invalid application of ‘sizeof’ to incomplete type ‘struct sigaction’ 
proc.c:174:2: error: invalid use of undefined type ‘struct sigaction’
cc1: warnings being treated as errors
proc.c:175:2: error: implicit declaration of function ‘sigaction’

最佳答案

只是

#define _XOPEN_SOURCE 700

在代码中的任何其他行之前,或使用 -D 选项编译以定义预处理器符号

gcc ... -D_XOPEN_SOURCE=700 ...

关于c - 结构 sigaction 不完整错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6491019/

相关文章:

在 C 中将一维数组转换为二维数组

c - 发送具有多个数字的唯一字符串客户端/服务器 TCP

c - 需要帮助编写此乘法代码

c - MPI 数组未声明

linux - 使用在双引号中包含空格的参数调用 std::system

linux - Bash 脚本记录平均 ping 时间,一天每 20 秒一次

linux - 从 shell 脚本的命令行解析参数

android - android Wifi ScanResult.level 值是什么意思?

c - 如何将取消请求从 main() 发送到线程?

c++ - 如何将 'on double clicked' 事件添加到 QTableWidget 中的整行?