C 注册函数处理程序

C 注册函数处理程序,c,signals,C,Signals,我不知道如何使用这个赋值方法,当signalsig作为参数给出时,该方法必须调用函数func void set_sig_handler(int sig,void (*func)(int)){ 谢谢。您可以使用,处理程序必须具有以下签名之一: /* this one matches your function */ void (*sa_handler)(int); /* use thhis one If SA_SIGINFO is specified */ void (*sa_sigact

我不知道如何使用这个赋值方法,当signal
sig
作为参数给出时,该方法必须调用函数
func

  void set_sig_handler(int sig,void (*func)(int)){
谢谢。

您可以使用,处理程序必须具有以下签名之一:

/* 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;
    }
}
#包括
....
无效集\u sig\u处理程序(int sig,void(*func)(int))
{
struct sigaction act={0};
/*设置信号处理器*/
act.sa_handler=func;
if(sigaction(sig,&act,NULL)<0){
佩罗尔(“sigaction”);
返回1;
}
}
如果可以使用,则处理程序必须具有以下签名之一:

/* 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;
    }
}
#包括
....
无效集\u sig\u处理程序(int sig,void(*func)(int))
{
struct sigaction act={0};
/*设置信号处理器*/
act.sa_handler=func;
if(sigaction(sig,&act,NULL)<0){
佩罗尔(“sigaction”);
返回1;
}
}