Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      SIG_ERR

      From cppreference.com
      <c‎ |program
       
       
      Program support utilities
      Program termination
      Unreachable control flow
      Communicating with the environment
      Memory alignment query
      Signals
      Signal types
      Non-local jumps
      Types
       
      Defined in header<signal.h>
      #define SIG_ERR /* implementation defined */

      A value of typevoid (*)(int). When returned bysignal, indicates that an error has occurred.

      [edit]Example

      Run this code
      #include <stdio.h>#include <stdlib.h>#include <signal.h> void signal_handler(int sig){printf("Received signal: %d\n", sig);} 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");returnEXIT_SUCCESS;}

      Output:

      Sending signal: 15Received signal: 15Exit main()

      [edit]References

      • C17 standard (ISO/IEC 9899:2018):
      • 7.14/3 Signal handling <signal.h> (p: 194)
      • 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>

      [edit]See also

      sets a signal handler for particular signal
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/program/SIG_ERR&oldid=140334"

      [8]ページ先頭

      ©2009-2025 Movatter.jp