std = c99を使用してstructsigactionをコンパイルする場合、「sa」のエラーストレージサイズは不明です



Error Storage Size Sa Isn T Known



void signal_exit_func(int signo) { printf('exit signo is %d ', signo) //CSingleton::instance().stop_server() } void signal_exit_handler() { struct sigaction sa memset(&sa, 0, sizeof(sa)) sa.sa_handler = signal_exit_func sigaction(SIGINT, &sa, NULL)//When ctrl+c is pressed, its effect is to send SIGINT signal sigaction(SIGTERM, &sa, NULL)//kill pid sigaction(SIGQUIT, &sa, NULL)//ctrl+ means to exit SIGQUIT //SIGSTOP and SIGKILL signals are not captureable, so the following two sentences are written without being written sigaction(SIGKILL, &sa, NULL)//kill -9 pid sigaction(SIGSTOP, &sa, NULL)//ctrl+z means stop //#define SIGTERM 15 //#define SIGKILL 9 //kill and kill -9, the two commands have the effect of killing the process in Linux, but the execution process of the two commands is very different, if used incorrectly in the program, it may cause some inexplicable phenomenon. //Execute the kill pid command, the system will send a SIGTERM signal to the corresponding program. //Execute the kill -9 pid command, the signal sent by the system to the corresponding program is SIGKILL, which is exit. The exit signal will not be blocked by the system, so kill -9 can successfully kill the process. }

コンパイルエラー:エラー:「sa」のストレージサイズが不明

構造体sigactionin



解決策は、ヘッダーファイルbits /sigaction.hを追加することです。

#include
#include




-----

参考記事: https://blog.csdn.net/gatieme/article/details/50991903




解決策1


これは、-std = gnu99など、コンパイル中に使用するコンパイラのタイプです。

解決策2


in #include 次に、sigactionヘッダーファイルを明示的に追加します

#include
  • 1

このようにして、コンパイラはsig​​actionの定義を明示的にコンパイルします。

ただし、この場合は注意が必要です#include しなきゃ#include その後

なぜならsignal合格する#error前処理を実行し、 `bits /sigaction.hに次が含まれているかどうかを確認する
ユーザーがそれを含めない場合、前処理段階でエラーが報告されます

#error 'Never include directly use instead.'
  • 1

画像