我不知道如何用这个赋值来做一个方法,func
当信号sig
作为参数给出时,它必须调用函数。
void set_sig_handler(int sig,void (*func)(int)){
谢谢。
您可以使用sigaction(),处理程序必须具有以下签名之一:
/* this one matches your function */
void (*sa_handler)(int);
/* use thhis one If SA_SIGINFO is specified */
void (*sa_sigaction)(int, siginfo_t *, void *);
例子:
#include <signal.h>
....
void set_sig_handler(int sig, void (*func)(int))
{
struct sigaction act= {0};
/* set signal handler */
act.sa_handler = func;
if (sigaction(sig, &act, NULL) < 0) {
perror ("sigaction");
return 1;
}
}