SA_RESETHAND 标志

问题描述

我编写了一个程序,用于在使用 SA_RESETHAND 建立信号处理程序时检查标志 sigaction效果

程序:

#define _XOPEN_SOURCE 700

#include <unistd.h>
#include <signal.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static void pexit(const char *fCall);
static void handler(int sig);

int
main() {
  struct sigaction action;

  action.sa_handler = handler;
  action.sa_flags = SA_RESETHAND;

  if (sigaction(SIGINT,&action,NULL) == -1) {
    pexit("sigaction");
  }

  printf("Hit Control-C,please\n");

  /* wait for signals indefinitely */
  for (;;) {
    pause();
  }

  /* should never get to this point */
  exit(EXIT_SUCCESS);
}

static void
handler(__attribute__((unused)) int signal) {
  printf("\tHello,I am a custom handler registered with SA_RESETHAND. Hit Control-C again to finish execution\n");
}

static void
pexit(const char *fCall) {
  perror(fCall);
  exit(EXIT_FAILURE);
}

此程序通过为 SIGINT 信号,在屏幕上打印一条消息。第二次发送信号时,采取认动作,进程终止

我的问题是如何用 static void pexit (const char * fCall); 函数替换此行 err_sys

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)