c++ - 如何使用 C++ 代码设置核心文件名?

标签 c++ linux

如何在 linux 中使用 c++ 代码设置核心文件名?

Linux 在二进制崩溃时转储核心文件,是否可以设置核心转储文件名?

最佳答案

在我的系统(带有内核 2.6.32 的 Ubuntu 10.04)上,man core 没有指示可以在逐个进程的基础上选择命名。然而,可以通过修改 /proc/sys/kernel/core_pattern 在系统范围内更改:

By default, a core dump file is named core, but the /proc/sys/kernel/core_pattern file (since Linux 2.6 and 2.4.21) can be set to define a template that is used to name core dump files. The template can contain % specifiers which are sub‐ stituted by the following values when a core file is created:

   %%  a single % character
   %p  PID of dumped process
   %u  (numeric) real UID of dumped process
   %g  (numeric) real GID of dumped process
   %s  number of signal causing dump
   %t  time of dump, expressed as seconds since the Epoch (00:00h, 1 Jan 1970, UTC)
   %h  hostname (same as nodename returned by uname(2))
   %e  executable filename (without path prefix)
   %c  core file size soft resource limit of crashing process (since Linux 2.6.24)

A single % at the end of the template is dropped from the core filename, as is the combination of a % followed by any character other than those listed above. All other characters in the template become a literal part of the core filename. The template may include '/' characters, which are interpreted as delimiters for directory names. The maximum size of the resulting core filename is 128 bytes (64 bytes in kernels before 2.6.19). The default value in this file is "core". For backward compatibility, if /proc/sys/kernel/core_pattern does not include "%p" and /proc/sys/kernel/core_uses_pid (see below) is non-zero, then .PID will be appended to the core filename.

关于c++ - 如何使用 C++ 代码设置核心文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7470169/

相关文章:

c# - 如何在 C# 中将数组放入结构中?

linux - 通过 SSH 和 GDB 启动进程?

linux - 我应该禁用还是启用透明大页以提高性能吗?

c++ - 类似于内核版本 2.6.9(或更低版本)的 inotify 的类似工具

用户更改后的 Android 插件和工具包配置

c++ - QGraphicsItem setTransformOriginPoint 似乎被忽略了

c++ - 为什么我不能通过 typedef 声明 friend ?

c++ - 用zlib提取一个gz文件内容并保存

c++ - 只有当您按回车键或到达文件末尾时,函数才会导致段错误

c++ - 在 C++ 代码中使用 qml 类型作为 QWindow