gpt4 book ai didi

在 Linux 中使用 signal.h 编译错误

转载 作者:IT王子 更新时间:2023-10-29 00:24:05 25 4
gpt4 key购买 nike

<分区>

我正在编写一个必须处理信号的 shell 程序。我的相关信号处理相关代码如下:

#include <signal.h>
...
#include <sys/types.h>
...
void installSigactions( int, struct sigaction* );

void handler_function( int signal_id );
...
/*define signal table*/
struct sigaction signal_action;

/*insert handler function*/
signal_action.sa_handler = handler_function;

/*init the flags field*/
signal_action.sa_flags = 0;

/*are no masked interrupts*/
sigemptyset( &signal_action.sa_mask );

/*install the signal_actions*/
sigaction( SIGINT, &signal_action, NULL );

编译给我以下警告和错误:

gcc -Wall -ggdb -ansi -static -pedantic -o os1shell2 os1shell2.c
os1shell2.c:35: warning: 'struct sigaction' declared inside parameter list
os1shell2.c:35: warning: its scope is only this definition or declaration,
which is probably not what you want
os1shell2.c: In function 'main':
os1shell2.c:66: error: storage size of 'signal_action' isn't known
os1shell2.c:75: warning: implicit declaration of function 'sigemptyset'
os1shell2.c:78: warning: implicit declaration of function 'sigaction'

谁能告诉我为什么会收到这些警告和错误?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com