The signal function in C language

Source: Internet
Author: User

    • Signal is a system call that is a special kind of interrupt that is used to invoke a program when a particular "software break" occurs. Interrupts are typically special cases that occur during program execution, such as referencing an illegal address in special memory, and floating-point numbers are removed by 0.
    • The prototype for signal () is:
      #include <signal.h>
      void(*signal(int hum,void(*func)(int)))(int);

    • The int parameter in signal and its meaning
      SIGHUP 1 A terminal hangs or the control process terminates
      SIGINT 2 A Keyboard interrupt (if the break key is pressed)
      sigqu99v 3 C Keyboard exit key is pressed
      Sigill 4 C Illegal Instruction
      SIGABRT 6 C Exit instruction issued by abort (3)
      SIGFPE 8 C Floating-point exception
      SIGKILL 9 AEF Kill signal
      SIGSEGV-C Invalid memory reference
      Sigpipe a pipeline rupture: write a pipeline without a read port
      SIGALRM a signal sent by alarm (2)
      SIGTERM A Stop Signal
      SIGUSR1 30,10,16 A User-defined signal 1
      SIGUSR2 31,12,17 A user-defined signal 2
      SIGCHLD 20,17,18 B Sub-process end signal
      Sigcont 19,18,25 Process continues (a process that has been stopped)
      SIGSTOP 17,19,23 DEF Terminating process
      SIGTSTP 18,20,24 D Control Terminal (TTY) press the STOP key
      Sigttin 21,21,26 D Background process attempts to read from the control terminal
      Sigttou 22,22,27 D Background process attempts to write from the control terminal

The following signals are not listed in Posix.1, but are listed in SUSv2

Sigbus 10,7,10 C Bus error (bad memory access)
Sigpoll a Sys v-defined pollable event, synonymous with Sigio
Sigprof 27,27,29 A Profiling timer to
Sigsys,-, C Invalid system call (SVID)
SIGTRAP 5 C Trace/Breakpoint Capture
Sigurg 16,23,21 B Socket Emergency condition (4.2 BSD)
SIGVTALRM 26,26,28 A Real time alarm clock signal (4.2 BSD)
SIGXCPU 24,24,30 C exceeds the set CPU time limit (4.2 BSD)
Sigxfsz 25,25,31 C exceeds the set file size limit (4.2 BSD)

(For Sigsys,sigxcpu,sigxfsz, and the Sigbus,linux default action for some machine architectures is a (terminate), SUSv2 is C (Terminate and dump core).

Here are some other signals.

Signal value processing action causes the signal

Sigiot 6 C io capture instruction, synonymous with SIGABRT
SIGEMT 7,-, 7
Sigstkflt-,16,-A coprocessor Stack Error
SIGIO 23,29,22 A I/O operation is now available (4.2 BSD)
SIGCLD-,-, A and SIGCHLD synonymous
SIGPWR 29,30,19 A power failure (System V)
Siginfo,-,-A and SIGPWR synonymous
Siglost-,-,-A file lock is missing
Sigwinch 28,28,20 B window size change (4.3 BSD, Sun)
sigunused-,31,-A not used signal ('ll be Sigsys)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Signal functions in the

C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.