简体   繁体   English

推荐信号赶上?

[英]Recommended signals to catch?

Currently, I catch SIGSEGV, send myself an email, and then abort() so I can get a core file and debug my program. 目前,我捕获了SIGSEGV,向自己发送了一封电子邮件,然后中止了(),以便获取核心文件并调试程序。 (If I did not catch, there would be no way that I would not know that my particular program segfaulted. My program is run in a separate server from my own.) (如果我没有发现问题,就无法避免我的特定程序被隔离。我的程序在与我自己的程序不同的服务器上运行。)

Are there any other signals that I should catch for debugging or for reasons that I should know about ? 我还有其他信号需要调试或出于某些我应该知道的原因吗?

What makes you think that a SEGV hasn't already corrupted your program memory so much that an attempt to send email won't fail spectacularly? 是什么让您认为SEGV 尚未严重破坏程序内存,以至于发送电子邮件的尝试不会以失败告终?

You should follow division of responsibility practices and monitor your program from a totally different program. 您应该遵循分工惯例,并从完全不同的程序中监视程序。

Simply have a (very simple so it's far less likely to fail) program which checks to make sure your primary program is still running and, if not, send you that email. 只需有一个(非常简单,因此失败的可能性很小)程序,该程序会检查以确保您的主程序仍在运行,如果没有,请向您发送该电子邮件。 You can even do defence-in-depth and run two checkers, both of which check the primary program and each other. 您甚至可以进行深度防御并运行两个检查器,这两个检查器都可以检查主程序并相互检查。

If you're paranoid like me, you can even run them on separate machines :-) 如果您像我一样偏执,甚至可以在单独的计算机上运行它们:-)

好吧,如果您的程序连接到控制台,则可能需要捕获SIGINT以转储/刷新您保留的所有缓冲区/日志。

You should probably not catch SIGSEGV / SIGBUS etc. 您可能不应该赶上SIGSEGV / SIGBUS等。

What you should do instead, is write a wrapper program which will detect if the subprocess exits from a signal, and identify the problem, then that process can carry out any required action. 您应该做的是编写一个包装程序,该程序将检测子进程是否从信号中退出并确定问题所在,然后该进程可以执行任何所需的操作。

If it is a server process, you probably also want to restart if it fails unexpectedly. 如果它是服务器进程,则如果它意外失败,您可能还希望重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM