- 论坛徽章:
- 0
|
linux下编程,调用了signal函数,但是居然没有接管到SIGINT信号。
gdb调试原始程序时,signal函数执行了,传递SIGINT信号到我的调试程序,但是我的程序没有接管。
另外在我的主程序中使用了sleep。
后来我写了下面的测试程序,和原始代码相同结构。但是gdb调试的时候,信号接管居然成功了。郁闷,定位不了。
请问高手,有没有这方面的信号接管不到的经历? 请指点一把。
以下是我的测试程序,类同我的原始代码。
- #include <unistd.h>;
- #include <stdlib.h>;
- #include <string>;
- #include <iostream>;
- bool gv_MainStarted = false; //! 主程序是否已经启动了
- #include <fcntl.h>;
- #include <signal.h>;
- #include <string.h>;
- #include <assert.h>;
- #include <memory.h>;
- #include <errno.h>;
- #include <sys/stat.h>;
- #ifdef __OS_UNIX__
- #include "xol.h" //! 所用到的库文件, unix下使用
- #endif //__OS_UNIX__
- using namespace std;
- //! 信号处理
- void signal_process(int sig_id)
- {
- cout << "sig_id : " <<sig_id <<endl;
-
- cout << gv_MainStarted <<endl;
-
- switch(sig_id)
- {
- case SIGINT:
- if( !gv_MainStarted)
- exit(0);
- cout << " SIGINT stop"<<endl;
- break;
- case SIGTERM:
- if( !gv_MainStarted )
- exit(0);
- cout << "SIGTERM stop"<<endl;
- break;
- case SIGSTOP:
- if( !gv_MainStarted )
- exit(0);
- cout << "SIGSTOP stop"<<endl;
- break;
- case SIGCONT:
- if( !gv_MainStarted )
- exit(0);
- cout << "SIGCONT stop"<<endl;
- break;
- }
- signal(sig_id, signal_process);
- }
- int main(int argc, char* argv[])
- {
-
- signal(SIGTERM, signal_process);
- signal(SIGINT, signal_process);
- signal(SIGSTOP, signal_process);
- signal(SIGCONT, signal_process);
-
- gv_MainStarted = true;
-
- signal(SIGTERM, signal_process);
- signal(SIGINT, signal_process);
- signal(SIGSTOP, signal_process);
- signal(SIGCONT, signal_process);
- int i;
- for (i = 1;i < 2; i = 1)
- {
- sleep(3);
- }
- return 0;
- }
复制代码 [/quote] |
|