Signal Handling–ref a software interrupt deli

    A program error such as dividing by zero or issuing an address outside the valid range.
  • A user request to interrupt or terminate the program. Most environments are set up to let a user suspend the program by typingC-z,or terminate it withC-c. Whatever key sequence is used,the operating system sends the proper signal to interrupt the process.
  • The termination of a child process.
  • Expiration of a timer or alarm.
  • A call tokillorraiseby the same process.
  • A call tokillfrom another process. Signals are a limited but useful form of interprocess communication.
  • An attempt to perform an I/O operation that cannot be done. Examples are reading from a pipe that has no writer (see section),and reading or writing to a terminal in certain situations (see section).

killandraise) generates its own particular kind of signal. The various kinds of signals are listed and described in detail in section.

openreturns-1. In general,errors that are necessarily associated with certain library functions are reported by returning a value that indicates an error. The errors which raise signals are those which can happen anywhere in the program,not just in library calls. These include division by zero and invalid memory addresses.

killwhose purpose is specifically to generate a signal.

SIGKILLandSIGSTOP,the action is fixed,but for most signals,the program has a choice: ignore the signal,specify ahandler function,or accept thedefault actionfor that kind of signal. The program specifies its choice using functions such assignalorsigaction(see section). We sometimes say that a handlercatchesthe signal. While the handler is running,that particular signal is normally blocked.

waitorwaitpidfunctions. (This is discussed in more detail in section.) The information it can get includes the fact that termination was due to a signal,and the kind of signal involved. If a program you run from a shell is terminated by a signal,the shell typically prints some kind of error message.


The value of this symbolic constant is the total number of signals defined. Since the signal numbers are allocated consecutively,NSIGis also one greater than the largest defined signal number.

longjmpto return control to the command level.

raiseorkillinstead of a real error.

`core’and is written in whichever directory is current in the process at the time. (On the GNU system,you can specify the file name for core dumps with the environment variableCOREFILE.) The purpose of core dump files is so that you can examine them with a debugger to investigate what caused the error.

TheSIGFPEsignal reports a fatal arithmetic error. Although the name is derived from “floating-point exception”,this signal actually covers all arithmetic errors,including division by zero and overflow. If a program stores integer data in a location which is then used in a floating-point operation,this often causes an “invalid operation” exception,because the processor cannot recognize the data as a floating-point number.

作者: dawei






在线咨询: QQ交谈