📅  最后修改于: 2020-09-26 15:51:59             🧑  作者: Mango
int raise( int sig );
raise 函数调用信号处理程序。如果未设置用户定义的函数来处理信号,则由实现定义,是忽略信号还是调用默认处理程序。
它在
sig
:要发送以进行处理的信号。它可以采用以下值之一:
成功时返回零,失败时返回非零。
#include
#include
using namespace std;
sig_atomic_t sig_value = 0;
void handler(int sig)
{
sig_value = sig;
}
int main()
{
signal(SIGABRT, handler);
cout << "Before signal handler is called" << endl;
cout << "Signal = " << sig_value << endl;
raise(SIGABRT);
cout << "After signal handler is called" << endl;
cout << "Signal = " << sig_value << endl;
return 0;
}
运行该程序时,输出为:
Before signal handler is called
Signal = 0
After signal handler is called
Signal = 6