SIG_ERR

< c‎ | program
定义于头文件 <signal.h>
#define SIG_ERR /* implementation defined */

void (*)(int) 类型值。为 signal 所返回时,指示出现了错误。

示例

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
 
void signal_handler(int signal)
{
    printf("Received signal %d\n", signal);
}
 
int main(void)
{
    /* 安装信号处理函数。 */
    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 15
Received signal 15
Exit main()

引用

  • C11 standard (ISO/IEC 9899:2011):
  • 7.14/3 Signal handling <signal.h> (p: 265)
  • C99 standard (ISO/IEC 9899:1999):
  • 7.14/3 Signal handling <signal.h> (p: 246)
  • C89/C90 standard (ISO/IEC 9899:1990):
  • 4.7 SIGNAL HANDLING <signal.h>

参阅

为特定的信号设置信号处理函数
(函数)