强制内核从FreeBSD上正常运行的活动程序中转储 [英] Force a core to dump from an active, normally running program on FreeBSD
问题描述
我正在为FreeBSD上的服务器编写错误处理代码.对于非常严重的错误,我想通过立即终止来避免数据损坏.这很容易,exit(3)
.在我退出之前,我输出了导致我到达那里的相关变量.但是,理想情况下,此终止将带有.core
,以便我可以全面调查是什么使我进入了这种灾难性(并且可能难以复制)状态.
I'm writing error handling code for a server on FreeBSD. For extremely serious errors I want to avoid data corruption by immediately terminating. That's easy, exit(3)
. Before I exit, I output my relevant variables that led me there. However, ideally, this termination would be accompanied by a .core
so that I could fully investigate what got me to this catastrophic (and likely hard to reproduce) state.
我该如何强迫这种情况发生?
How can I force this to happen?
推荐答案
kill -QUIT process_id
将导致正在运行的进程发生核心转储(假设资源限制允许这样做).
kill -QUIT process_id
will cause a core dump from a running process (assuming that resource limits allow it).
或参见man 3 abort
有关导致程序转储自身的信息.
Or see man 3 abort
for causing a program to dump itself.
已添加:在交互式外壳中,可以使用退出键(通常为 Ctrl + \ )使正在运行的程序中止运行发送SIGQUIT,就像更常见的 Ctrl + C 发送SIGINT一样.这与kill -QUIT…
相同,如果您在控制终端上,则输入起来更容易.如果您的默认退出密钥不同,请参见man 1 stty
.
Added: From an interactive shell, a running program can be made to abort with the quit key, usually Ctrl+\, which sends a SIGQUIT just as the more common Ctrl+C sends a SIGINT. This is identical to the kill -QUIT…
it's just easier to type if you are on the controlling terminal. See man 1 stty
if your default quit key is different.
这篇关于强制内核从FreeBSD上正常运行的活动程序中转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!