signal

signal

======

======





Syntax

⠪

-----

-----





#include <signal.h>

#include <signal.h>





void       (*signal(int sig, void (*func)(int)))(int);

void       (*signal(int sig, void (*func)(int)))(int);





Description

ᠭ

----------

----------





Signals are generated in response to some exceptional behavior of the program, such as division by 0.  A signal can also report some asynchronous event outside the program, such as someone pressing a Ctrl-Break key combination.

   ⢥  ஥ ᪫⥫쭮  ணࠬ, ⨯   0.   ⠪ ᮮ  ஬ ᨭ஭ ᮡ⨥  ணࠬ, ⨯   -    ctrl-break-  뢠.





Signals are numbered 0..255 for software interrupts and 256..287 for exceptions (exception number plus 256); other implementation-specific codes are specified in `<signal.h>' (see below).  Every signal is given a mnemonic which you should use for portable programs.

 ஭㬥஢ 0 .. 255  ணࠬ 뢠  256 .. 287  ᪫祭 ( ᪫祭  256); 㣨 ᯥ᪨  ॠ樨  ।  " <signal.h> ' (. ).  ᨣ    ,    ᯮ짮  ७ᨬ ணࠬ.





The default handling for all the signals is to print a traceback (a stack dump which describes the sequence of function calls leading to the generation of the signal) and abort the program.

 㬮砭 ࠡ⪠   ᨣ   traceback ( ⥪,  뢠 ᫥⥫쭮 맮 㭪樨 ਢ   ஦ ᨣ)  ਩ ४饭 ࠡ ணࠬ.





This function allows you to change the default behavior for a specific signal.  It registers FUNC as a signal handler for signal number SIG. After you register your function as the handler for a particular signal, it will be called when that signal occurs.  The execution of the program will be suspended until the handler returns or calls `longjmp' (longjmp.).

 㭪      㬮砭   ᯥ᪮ ᨣ.  ॣ FUNC  ࠡ稪 ᨣ   ᨣ SIG. ᫥ ⮣,   ॣ  㭪  ࠡ稪  ᯥ᪮ ᨣ,  㤥 뢠,   ᨣ ந室. 믮 ணࠬ 㤥 ਮ⠭    ࠡ稪  뢠 "longjmp" (longjmp.).





You may pass SIG_DFL as the value of FUNC to reset the signal handling for the signal SIG to default (also __djgpp_exception_toggle, for a quick way to restore all the signals' handling to default), SIG_ERR to force an error when that signal happens, or SIG_IGN to ignore that signal.  Signal handlers that you write are regular C functions, and may call any function that the ANSI/POSIX specs say are valid for signal handlers.  For maximum portability, a handler for hardware interrupts and processor exceptions should only make calls to `signal', assign values to data objects of type `volatile sig_atomic_t' (defined as `int' on `<signal.h>') and return.  Handlers for hardware interrupts need also be locked in memory (so that the operation of virtual memory mechanism won't swap them out), locking memory regions  Handlers for software interrupts can also terminate by calling `abort', `exit' or `longjmp'.

  । SIG_DFL  祭 FUNC, ⮡  ࠡ ᨣ  ᨣ SIG  祭  㬮砭 (⠪ __ djgpp_exception_toggle,  ண ᯮᮡ ⠭ ࠡ  ᨣ  祭  㬮砭), SIG_ERR, ⮡ 뤠 訡,   ᨣ, 砥,  SIG_IGN   ᨣ. ࠡ稪 ,   । - ࠢ 㭪樨 C,   뢠  㭪,  ANSI/POSIX ᯥ䨪樨 ᪠  ࠡ稪 ᨣ.  ᨬ쭮 ७ᨬ, ࠡ稪   뢠  ᪫祭   ⮫쪮  맮 `signal',  祭  ꥪ⠬  ⨯ "volatile sig_atomic_t' (।  "int"  " <signal.h> ')  . ࠡ稪   뢠  ⠪  ஢묨   (⠪, ⮡  㠫쭮 堭    ᢮   ),   , ࠡ稪  ணࠬ 뢠  ⠪ ,  뢠 `abort', `exit' or `longjmp'.





The following signals are defined on `<signal.h>':

騥 ᨣ ।  " <signal.h> ':





`SIGABRT'

`SIGABRT'

The Abort signal.  Currently only used by the `assert' macro to terminate the program when an assertion fails (assert.).

 ਩ ४饭 ࠡ.  饥 ६ ᯮ ⮫쪮  ப `assert', ⮡  ணࠬ,  ந室 ᡮ (`assert')..





`SIGFPE'

`SIGFPE'

The Floating Point Error signal.  Generated in case of divide by zero exception (Int 00h), overflow exception (Int 04h), and any x87 co-processor exception, either generated by the CPU (Int 10h), or by the co-processor itself (Int 75h).

   饩 ⮩.   砥 ᪫祭    (Int 00h), ᪫祭 ९ (Int 04h),   x87 ᪫祭 ᮯ,  ᣥ஢ CPU (Int 10h),  ᮯ஬ ।⢥ (Int 75h).





`SIGILL'

`SIGILL'

The Invalid Execution signal.  Currently only generated for unknown/invalid exceptions.

 ⨬ 믮.  饥 ६ ⮫쪮    / ⨬ ᪫祭.





`SIGINT'

`SIGINT'

The Interrupt signal.  Generated when a `Ctrl-C' or `Ctrl-Break'(Int 1Bh) key is hit.  Note that when you open the console in binary mode, or switch it to binary mode by a call to `setmode' (setmode.), generation of `SIGINT' as result of `Ctrl-C' key is disabled.  This is so for programs (such as Emacs) which want to be able to read the `^C' character as any other character. Use the library function `__djgpp_set_ctrl_c' to restore `SIGINT' generation when `Ctrl-C' is hit, if you need this. __djgpp_set_ctrl_c, for details on how this should be done. `Ctrl-Break' always generates `SIGINT'.

 뢠. ,  "Ctrl-C"  "Ctrl-Break" (Int 1Bh)  .     ,   뢠 ᮫  筮 ०,  砥    ० 饭  "setmode" (setmode),  "SIGINT"  १ ⮣   "Ctrl-C" ஢.  - ⠪  ணࠬ (⨯ Emacs)    ᯮᮡ묨  " ^ C ' ᨬ   㣮 ᨬ. ᯮ  㭪 " __ djgpp_set_ctrl_c ', ⮡ ⠭  "SIGINT",  "Ctrl-C" , ᫨  㦤  ⮬. . __ djgpp_set_ctrl_c,  ஡⥩  ⮬,     믮. "Ctrl-Break" ᥣ  "SIGINT".





DJGPP hooks the keyboard hardware interrupt (Int 09h) to be able to generate `SIGINT' in response to `Ctrl-C' key; you should be aware of this when you install a handler for the keyboard interrupt.

DJGPP 墠뢠 ⭮ 뢠   (Int 09h) ⮡  ᯮᮡ ஢ "SIGINT"  ⢥   "Ctrl-C";    ,   ⠭ ࠡ稪  뢠 .





`SIGSEGV'

`SIGSEGV'

The invalid storage access (Segmentation Violation) signal.Generated in response to any of the following exceptions: Bound range exceeded in BOUND instruction (Int 05h), Double Exception or an exception in the exception handler (Int 08h), Segment Boundary violation by co-processor (Int 09h), Segment Not Present (Int 0Bh), Stack Fault (Int 0Ch), General Protection Violation (Int 0Dh), or Page Fault (Int 0Eh).  Note that Int 09h is only generated on 80386 processor; i486 and later CPUs cause Int 0Dh when the co-processor accesses memory out of bounds.

 ⨬ 㯠   (襭 樨).   ⢥    ᫥ ᪫祭: ࠭  ॢ襭   (Int 05h),  ᪫祭  ᪫祭  ணࠬ ॠ樨  ᮡ  (Int 08h), 襭 ࠭筮 ᥣ ᮯ஬ (Int 09h),    (Int 0Bh), 訡 ⥪ (Int 0Ch), 饥 襭  (Int 0Dh),  ⢨ ࠭ (Int 0Eh).  ,  Int 09h ⮫쪮 ᣥ஢  80386 ; i486    CPU 뢠 Int 0Dh,  ᮯ 頥    ࠭.





`SIGTERM'

`SIGTERM'

The Termination Request signal.  Currently unused.

  ନ.  饥 ६ ᯮ.





The signals below this are not defined by ANSI C, and cannot be used when compiling under `-ansi' option to `gcc'.

  ⮣  ।  ANSI,   ᯮ짮  樥 "gcc"  樥 `-ansi'.





`SIGALRM'

`SIGALRM'

The Alarm signal.  Generated after certain time period has passed after a call to `alarm' library function (alarm.).

਩ ᨣ.  ᫥ ண ਮ ६ ᫥ 饭  筮 㭪樨 `alarm'.





`SIGHUP'

`SIGHUP'

The Hang-up signal.  Currently unused.

 ४饭 裡. ᯮ.





`SIGKILL'

`SIGKILL'

The Kill signal.  Currently unused.

 㭨⮦. ᯮ.





`SIGPIPE'

`SIGPIPE'

The Broken Pipe signal.  Currently unused.

 ࠧ⣮ . ᯮ.





`SIGQUIT'

`SIGQUIT'

The Quit signal.  Currently unused.

 室. ᯮ.





`SIGUSR1'

`SIGUSR1'

User-defined signal no. 1.

।塞 짮⥫ ᨣ  1.





`SIGUSR2'

`SIGUSR2'

User-defined signal no. 2.

।塞 짮⥫ ᨣ  2.





The signals below are not defined by ANSI C and POSIX, and cannot be used when compiling under either `-ansi' or `-posix' options to `gcc'.

   । ANSI C  POSIX,    ᯮ짮  ஢  ﬨ "-ansi"  "-posix"  "gcc".





`SIGTRAP'

`SIGTRAP'

The Trap Instruction signal.  Generated in response to the Debugger Exception (Int 01h) or Breakpoint Exception (Int 03h).

  誨. ஢  ⢥  ᪫祭 ⫠稪 (Int 01h)  ᪫祭 ஫쭮 窨 (Int 03h).





`SIGNOFP'

`SIGNOFP'

The No Co-processor signal.  Generated if a co-processor (floating-point) instruction is encountered when no co-processor is installed (Int 07h).

 ⢨ ᮯ. , ᫨   ᮯ ( 饩 ⮩),   ᮯ  ⠭ (Int 07h).





`SIGTIMR'

`SIGTIMR'

The Timer signal.  Used by the `setitimer' and `alarm' functions (setitimer, alarm).

 . ᯮ "setitimer"  "alram" 㭪ﬨ (setitimer, alram).





`SIGPROF'

`SIGPROF'

The Profiler signal.  Used by the execution profile gathering code in a program compiled with `-pg' option to `gcc'.

 䨫஢騪. ᯮ 䠩஬,  樨  樥 "-PG"  "gcc".





Return Value

Return Value

-----------

-----------





The previous handler for signal SIG, or `SIG_ERR' if the value of SIG is outside legal limits.

।騩 ࠡ稪  ᨣ SIG,  "SIG_ERR", ᫨ 祭 SIG -  ⨬.





Signal Mechanism Implementation Notes

ਬ砭  堭 

------------------------------------

------------------------------------





Due to subtle aspects of protected-mode programs operation under MS-DOS, signal handlers cannot be safely called from hardware interrupt handlers.  Therefore, DJGPP exception-handling mechanism arranges for the signal handler to be called on the first occasion that the program is in protected mode and touches any of its data.  This means that if the exception occurs while the processor is in real mode, like when your program calls some DOS service, the signal handler won't be called until that call returns.  For instance, if you call `read' (or `scanf', or `gets') to read text from the console and press `Ctrl-C', you will have to press `Enter' to terminate the `read' call to cause the signal handler for `SIGINT' to be called.  Another significant implication of this implementation is that when the program isn't touching any of its data (like in very tight loops which only use values in the registers), it cannot be interrupted.

- ⮭ ᯥ⮢ ᯮ ணࠬ  饭 ०  -, ࠡ稪 ᨣ   ᭮ 뢠  ࠡ稪  뢠. ⥫쭮, DJGPP 堭 ࠡ⪨ ᮡ 権 ਭ , ⮡  ࠡ稪 ᨣ  맢   砩,  ணࠬ 室  饭 ०  ࠣ    .  砥 , ᫨ ᪫祭 ந室,   ६   室  ॠ쭮 ०,  ⮬,   ணࠬ 뢠 ஥ 㦨 DOS, ࠡ稪 ᨣ  㤥 뢠    饭. ਬ, ᫨  뢠 "read" ( "scanf",  " gets') ⮡  ⥪     " Ctrl-C ',  㤥   "enter", ⮡  " read ' 饭, ⮡ ⠢ ࠡ稪 ᨣ " SIGINT ' 뢠. 㣠 ⥫쭠  ⮩ ॠ樨  , ,  ணࠬ  ࠣ    (  祭  横,  ⮫쪮 ᯮ 祭  ॣ),      ࢠ.









