当前位置: 技术问答>linux和unix
Linux对信号的处理
来源: 互联网 发布时间:2016-10-31
本文导语: 我在linux suse10系统上写了下面一个小程序, 使用g++ -g -w test.cpp -o test 然后执行./test & 报Illegal instruction错误,然后进程退出,我在开始就将SIGILL信号设置为忽略信号了,为什么还会报错退出。 Illegal instruction报错我知道...
我在linux suse10系统上写了下面一个小程序,
使用g++ -g -w test.cpp -o test
然后执行./test &
报Illegal instruction错误,然后进程退出,我在开始就将SIGILL信号设置为忽略信号了,为什么还会报错退出。
Illegal instruction报错我知道,是因为printf("%sn", strName); 语句中strName类型为string类型。
接着我修改为正确的代码,执行会打印
this is a test code!
接着我使用kill -4 17552向test进程发送信号,这时候进程忽略了SIGILL。没有退出。
本人新手,请知道的帮我解释下。
test.cpp
#include
#include
#include
using namespace std;
int main()
{
sigset(SIGILL, SIG_IGN);
signal(SIGILL, SIG_IGN);
string strName = "this is a test code!";
printf("%sn", strName);
//printf("%sn", strName.c_str());
while(1)
{
sleep(5);
}
}
|
NOTES
The effects of signal() in a multi-threaded process are unspecified.
According to POSIX, the behavior of a process is undefined after it ignores a SIGFPE, SIGILL, or SIGSEGV signal that was not generated by kill(2) or
raise(3). Integer division by zero has undefined result. On some architectures it will generate a SIGFPE signal. (Also dividing the most negative inte-
ger by -1 may generate SIGFPE.) Ignoring this signal might lead to an endless loop.
|
man里面说得很清楚呀
According to POSIX, the behavior of a process is undefined after it ignores a SIGFPE, SIGILL, or SIGSEGV signal that was not generated by kill(2) or raise(3).
ignore的动作没有定义,就是你ignore了,等于没有ignore。
According to POSIX, the behavior of a process is undefined after it ignores a SIGFPE, SIGILL, or SIGSEGV signal that was not generated by kill(2) or raise(3).
ignore的动作没有定义,就是你ignore了,等于没有ignore。
|
有的 仔细看看