Signal

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值