0

美好的一天,我有下一个代码:

server s;
namespace signals_handler
{
    //sig_atomic_t is_stop=0;
    void signal_handler(int sig)
    {
        if(sig==SIGHUP)
        {
            printf("recived :SIGHUP\n");
            s.restart();
        }
        else if(sig==SIGINT)
        {
            printf("recived :SIGINT\n");
            //is_stop = 1;
            s.interupt();
        }
    }
}
int main(int argc, char* argv[])
{
    signal(SIGHUP, signals_handler::signal_handler);
    signal(SIGINT, signals_handler::signal_handler);
    s.start();
    s.listen();
    return 0;
}

当我开始执行此代码时,我可以捕获 SIGHUP,SIGINT 不会为我的应用程序提供,但调试器在“侦听”功能中停止但没有移动到信号处理程序功能,为什么会发生这种情况以及我做错了什么?

4

1 回答 1

1

这是正常的。gdb捕捉到信号。从手册:

通常,gdb 设置为让 SIGALRM 等非错误信号静默传递给您的程序(以免干扰它们在程序运行中的作用),但在发生错误信号时立即停止您的程序。您可以使用 handle 命令更改这些设置。

要更改行为,请使用:

handle SIGINT nostop pass

处理信号 [关键字...] 更改 gdb 处理信号信号的方式。信号可以是信号的编号或其名称(开头有或没有'SIG');'low-high' 形式的信号编号列表;或“全部”一词,意思是所有已知的信号。下面描述的可选参数关键字说明了要进行的更改。

handle 命令允许的关键字可以缩写。他们的全名是:

nostop
    gdb should not stop your program when this signal happens. It may still print a message telling you that the signal has come in.
stop
    gdb should stop your program when this signal happens. This implies the print keyword as well.
print
    gdb should print a message when this signal happens.
noprint
    gdb should not mention the occurrence of the signal at all. This implies the nostop keyword as well.
pass
noignore
    gdb should allow your program to see this signal; your program can handle the signal, or else it may terminate if the signal is fatal and not handled. pass and noignore are synonyms.
nopass
ignore
    gdb should not allow your program to see this signal. nopass and ignore are synonyms. 
于 2013-06-05T07:13:58.003 回答