Signal

来源:互联网 发布:淘宝质检报告处罚 编辑:程序博客网 时间:2024/05/01 23:47

A signal is an event generated by the UNIX and Linux systems in response to some condition, upon receipt of which a process may in turn take some action. We use the term raise to indicate the generation of a signal, and the term catch to indicate the receipt of a signal. Signals are raised by some error conditions, such as memory segment violations, floating-point processor errors, or illegal instructions. They are generated by the shell and terminal handlers to cause interrupts and can also be explicitly sent from one process to another as a way of passing information or modifying behavior. In all these cases, the programming interface is the same. Signals can be raised, caught and acted upon, or(for some at least) ignoreed.

 

Signal names are defined by including the header file signal.h. They all begin with SIG.

 

Programs can handle signals using the signal library function:

The signal to be caught or ignored is given as argument sig. The function to be called when the specified signal is received is given as func. The signal function itself returns a function of the same type, which is the previous value of the function set up to handle this signal, or one of these two special values:

SIG_IGN:Ignore the signal;    SIG_DFL:Restore default behavior.

 

Sending Signals:

A process may send a signal to another process, including itself, by calling kill. The call will fail if the program doesn't have permission to send the signal, often because the target process is owned by another user. This is the program equivalent of the shell command of the same name.

 

A Robust Signals Interface:

The  sigaction structure, used to define the actions to be taken on receipt of the signal specified by sig, is defined in signal.h and has at least the following members:

 

The header file signal.h defines the type sigset_t and functions used to manipulate sets of signals.

原创粉丝点击