signal
来源:互联网 发布:php 将数组分割成三段 编辑:程序博客网 时间:2024/05/03 06:54
转载自:http://www.cplusplus.com/reference/csignal/signal/
signal
void (*signal(int sig, void (*func)(int)))(int);
Specifies a way to handle the signals with the signal number specified bysig.
Parameter func specifies one of the three ways in which a signal can be handled by a program:
- Default handling (SIG_DFL): The signal is handled by the default action for that particular signal.
- Ignore signal (SIG_IGN): The signal is ignored and the code execution will continue even if not meaningful.
- Function handler: A specific function is defined to handle the signal.
Either SIG_DFL or SIG_IGN is set as the default signal handling behavior at program startup for each of the supported signals .
Parameters
- sig
- The signal value to which a handling function is set. The following macro constant expressions identify standard signal values:
macro signal SIGABRT(Signal Abort) Abnormal termination, such as is initiated by the abort function.SIGFPE(Signal Floating-Point Exception) Erroneous arithmetic operation, such as zero divide or an operation resulting in overflow (not necessarily with a floating-point operation).SIGILL(Signal Illegal Instruction) Invalid function image, such as an illegal instruction. This is generally due to a corruption in the code or to an attempt to execute data.SIGINT(Signal Interrupt) Interactive attention signal. Generally generated by the application user.SIGSEGV(Signal Segmentation Violation) Invalid access to storage: When a program tries to read or write outside the memory it has allocated.SIGTERM(Signal Terminate) Termination request sent to program.
Each library implementation may provide additional signal value macro constants that can be used with this function.
Notice that not all running environments are required to generate automatic signals, not even in the specific cases described above, although all running environments must deliver signals generated by a explicit call to theraise function. - func
- A pointer to a function. This may either be a function defined by the programmer or one of the following predefined functions:
SIG_DFLDefault handling: The signal is handled by the default action for that particular signal.SIG_IGNIgnore Signal: The signal is ignored.
If a function, it should follow the following prototype (with C linkage):void handler_function (int parameter);
Return value
The return type is the same as the type of parameter func.
If the request is successful, the function returns a pointer to the particular handler function which was in charge of handling this signal before the call, if any. Or eitherSIG_DFL or SIG_IGN if before the call the signal was being handled by the default handler or was being ignored, respectivelly.
If the function was not successful in registering the new signal handling procedure, it returnsSIG_ERR and errno may be set to a positive value.
Example
1234567891011121314151617181920212223242526
/* signal example */#include <stdio.h> /* printf */#include <signal.h> /* signal, raise, sig_atomic_t */sig_atomic_t signaled = 0;void my_handler (int param){ signaled = 1;}int main (){ void (*prev_handler)(int); prev_handler = signal (SIGINT, my_handler); /* ... */ raise(SIGINT); /* ... */ printf ("signaled is %d.\n",signaled); return 0;}
signaled is 1.
Data races
Undefined: calling this function in a multi-threaded program causes undefined behavior.
Exceptions (C++)
No-throw guarantee: this function never throws exceptions.
- signal
- signal
- Signal
- signal
- signal
- signal
- signal
- signal
- signal()
- signal
- signal
- signal
- signal
- Signal
- signal
- signal
- signal
- signal
- android-async-http-master - 网络连接
- asp.net中BeginInvoke和EndInvoke方法使用方法
- 2.13-if
- c中位运行的应用
- python笔记002
- signal
- 编程开发中浪费时间和资源的7个误区
- C#高级编程五十六天----可观察的集合ObservableCollection
- 关于cocoaPods
- const指针与指向const对象的指针
- int *p=12这里是不可以这样做的,指针要开辟空间
- SDWebImage情况处理(不断更行)
- Android 控件开发之ImageButton
- 软件开发工具(三)——理论与开发过程