如何在unix上找到没有日志文件的死进程的原因?
这是一道面试题。
开发人员启动了一个流程。 但当客户想要使用该流程时,他发现该流程没有运行。 开发者登录后发现进程死掉了。开发人员如何知道出了什么问题?
跟进:一个正在运行的进程,应该将日志写入文件。但文件中没有日志。开发人员如何弄清楚这个过程中发生了什么?
我认为 : 如果程序可以重新运行,我将使用 gdb 来跟踪该进程。 如果没有,请检查进程(应用程序)的输出文件。 或者,将 print 添加到代码中。
但是,是否有其他方法可以通过引用操作系统生成的一些信息来做到这一点?
This is an interview question.
A developer started a process.
But when a customer wants to use the process, he found the process wasn't running.
The developer logged in and found the process died. How can the developer know what was wrong?
Follow up: a running process which is supposed to write logs to a file. But there are no logs in the file. How can the developer figure out what's going on in the process?
I think :
If the program can be re-run, i will use gdb to track the process.
If not, check the output file from the process (the application program).
or, add print to the code.
But, are there other ways to do it by referring some information generated by OS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您有磁盘空间和空闲 CPU 能力,您可以保留
strace
跟随程序捕获导致退出的序列。如果程序在没有留下任何痕迹的情况下死亡,一个可能的原因是内存不足 (OOM) 杀手。如果它终止了您的进程,则会在内核日志中留下一条消息。
从同一个答案中, 进程可以修改accounting,通过告诉您退出代码和退出时间来提供一些线索。
If you have the disk space and spare CPU power, you can leave
strace
following the program to catch the sequence leading up to exit.One possible cause if the program died without leaving any trace is the Out-Of-Memory (OOM) killer. This will leave a message in the kernel log if it kills your process.
From the same answer, process accounting can be modified to provide some clues by telling you the exit code along with the exit time.
核心转储
是一种选择。core dump
is one option.有时程序不会创建核心转储。在这种情况下,了解软件的退出代码可能会有所帮助。
因此,您可以使用下面的这个脚本来启动您的软件并记录其退出状态以查找其退出原因。
例子 :
Sometimes programs don't create core dumps. In this case knowing the exit code of your software may help.
So you can use this script below to start your software and log its exit status for finding its exit reason.
Example :
...使用像 gdb 这样的调试器...
... use a debugger like gdb ...