©
This document uses PHP Chinese website manual Release
在头文件<signal.h>中定义 | ||
---|---|---|
#define SIG_ERR / *实现定义* / |
void(*)(int)类型的值。 当通过信号返回时,表示发生了错误。
#include <stdio.h>#include <stdlib.h>#include <signal.h> void signal_handler(int signal){ printf("Received signal %d\n", signal);} int main(void){ /* Install a signal handler. */ if (signal(SIGTERM, signal_handler) == SIG_ERR) { printf("Error while installing a signal handler.\n"); exit(EXIT_FAILURE); } printf("Sending signal %d\n", SIGTERM); if (raise(SIGTERM) != 0) { printf("Error while raising the SIGTERM signal.\n"); exit(EXIT_FAILURE); } printf("Exit main()\n"); return EXIT_SUCCESS;}
输出:
Sending signal 15Received signal 15Exit main()
C11标准(ISO / IEC 9899:2011):
7.14 / 3信号处理<signal.h>(p:265)
C99标准(ISO / IEC 9899:1999):
7.14 / 3信号处理<signal.h>(p:246)
C89 / C90标准(ISO / IEC 9899:1990):
4.7信号处理<signal.h>
signal | 设置特定信号的信号处理程序(功能) |
---|
| SIG_ERR的C ++文档 |