Providing/passing argument to signal handler

后端 未结 7 1207
夕颜
夕颜 2020-12-02 10:29

Can I provide/pass any arguments to signal handler?

/* Signal handling */
struct sigaction act;
act.sa_handler = signal_handler;
/* some more settings */
         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 11:06

    A signal handler registration is already a global state equivalent to global variables. So it's no greater offense to use global variables to pass arguments to it. However, it's a huge mistake (almost certainly undefined behavior unless you're an expert!) to do anything from a signal handler anyway. If you instead just block signals and poll for them from your main program loop, you can avoid all these issues.

提交回复
热议问题