创建注册信号处理器

创建注册信号处理器

#include <signal.h>
int catch_signal(int sig, void (*handler) (int))
{
  struct sigaction action;
  action.sa_handler = handler;
  sigemptyset(&action.sa_mask);
  action.sa_flags = 0;
  return sigaction (sig, &action, NULL);
}