2
我在隨機時間內收到分段錯誤。
我註冊的信號,但信號處理程序段錯誤發生時不叫沒有爲dlopen或dlclose調用信號處理程序
#include <unistd.h>
#include <dlfcn.h>
#include <iostream>
#include <signal.h>
#include <execinfo.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
using namespace std;
void Handler(int sig)
{
cout << "handler called " << strsignal(sig) << endl;
exit(1);
}
int main()
{
cout << "Testing crash !" << endl;
signal(SIGSEGV, Handler);
signal(SIGINT, Handler);
signal(SIGABRT, Handler);
for (int i = 0; i < 10; i++)
{
cout << i << " Before open" << endl;
void *handler = dlopen("/home/user/Test.so", RTLD_LAZY);
if (handler)
{
cout << i << " Before close" << endl;
dlclose(handler);
cout << i << " After close" << endl;
}
else
{
cout << "Error " << dlerror() << endl;
}
}
return 0;
}
輸出:
RUN1
Testing crash !
0 Before open
0 Before close
0 After close
1 Before open
1 Before close
Segmentation fault (core dumped)
RUN2
0 Before open
0 Before close
0 After close
1 Before open
1 Before close
1 After close
Segmentation fault (core dumped)
問題是信號處理程序不叫分析問題
分段錯誤是SIGSEGV。當您按下Ctrl-C時會觸發SIGINT。 –
順便說一句,有raise()系統調用,如果內核是越野車,使用kill可能只是非確定性的? –
@PaulStelian。我試圖刪除你提到的東西,即使我得到同樣的結果。如果你想我會粘貼更新的代碼 –