每个进程可配置的核心转储目录
有没有办法为特定进程配置核心转储文件的放置目录?
我有一个用 C++ 编写的守护进程,我想为其配置核心转储目录。 (可选)文件名模式也应该是可配置的。
我知道/proc/sys/kernel/core_pattern
,但是这会改变全局的模式和目录结构。
Apache 有指令 CoreDumpDirectory
- 所以这似乎是可能的。
Is there a way to configure the directory where core dump files are placed for a specific process?
I have a daemon process written in C++ for which I would like to configure the core dump directory. Optionally the filename pattern should be configurable, too.
I know about /proc/sys/kernel/core_pattern
, however this would change the pattern and directory structure globally.
Apache has the directive CoreDumpDirectory
- so it seems to be possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您不能为每个进程设置它。核心文件被转储到进程的当前工作目录,或者如果模式包含目录,则转储到 /proc/sys/kernel/core_pattern 中设置的目录。
apache 中的 CoreDumpDirectory 是一个 hack,apache 为所有导致 core dump 的信号注册信号处理程序,并更改其信号处理程序中的当前目录。
No, you cannot set it per process. The core file gets dumped either to the current working directory of the process, or the directory set in /proc/sys/kernel/core_pattern if the pattern includes a directory.
CoreDumpDirectory in apache is a hack, apache registers signal handlers for all signals that cause a core dump , and changes the current directory in its signal handler.
可以使用 core_pattern 文件的“|command”机制来实现。执行的命令可以根据需要创建目录和文件。该命令可以在参数中传递以下说明符(参见 man 5核心):
例如,可以创建一个脚本(例如名为 crash.sh),如下所示:
在 shell 中:
创建一个崩溃的示例程序(例如失败.c):
编译程序(生成多个可执行文件)并调整当前 shell 中的核心文件大小:
多次运行失败的程序以获得多个进程 ID:
查看 /tmp,其中 core_pattern 重定向核心转储:
It is possible to make it using the "|command" mechanism of the core_pattern file. The executed command can create the directories and files as needed. The command can be passed the following specifiers in the parameters (cf. man 5 core):
For example, it is possible to create a script (e.g. named crash.sh) as follow:
In the shell:
Create an example program which crashes (e.g. fail.c):
Compile the program (make several executables) and adjust the core file size in the current shell:
Run the failing programs several times to have multiple processes ids:
Look at /tmp where the core_pattern redirects the core dumps: