有没有办法将 sigaction() 发送到具有多个参数的信号处理程序?
每次收到 SIGINT 时,我都会使用 sigaction() 执行操作。我见过的所有教程都使用这个原型作为信号处理程序
void sig_handler(int sig);
是否有一种方法可以使其接受更多参数,从而满足我的需求?例如
void sig_handler(char* surname, int age);
这是我的代码:
void sig_handler(int sig) {
printf("SIGINT(%d) received\n", sig);
}
int main( ){
struct sigaction act;
act.sa_handler=sig_handler;
sigaction(SIGINT, &act, NULL);
while(1){};
return 0 ;
}
I am using sigaction() to perform an action every time SIGINT is received. All tutorials I have seen use this prototype as a signal handler
void sig_handler(int sig);
Is there a way somehow to make this to take more parameters so it suits my needs? So for example
void sig_handler(char* surname, int age);
This is my code:
void sig_handler(int sig) {
printf("SIGINT(%d) received\n", sig);
}
int main( ){
struct sigaction act;
act.sa_handler=sig_handler;
sigaction(SIGINT, &act, NULL);
while(1){};
return 0 ;
}
不直接,但您可以设置一个全局变量来告诉您的 sig_handler() 做什么。
Not directly, but you could set a global variable that tells your
sig_handler()
what to do.