c - 以编程方式打开核心/故障转储

标签 c linux

我知道我能跑 “ulimit -c 无限制”

在 shell 中为当前用户打开核心转储。 我想知道如何从 C 中以编程方式执行此操作?

我看到有一个 ulimit 调用,但它已被弃用,取而代之的是 get/setrlimit。 我想知道的是允许故障转储的对 setrlimit 的等效调用是什么 生成?

最佳答案

我找到了可行的解决方案。现在正在创建核心文件。

struct rlimit core_limit;
core_limit.rlim_cur = RLIM_INFINITY;
core_limit.rlim_max = RLIM_INFINITY;

if (setrlimit(RLIMIT_CORE, &core_limit) < 0)
    fprintf(stderr, "setrlimit: %s\nWarning: core dumps may be truncated or non-existant\n", strerror(errno));

致谢:http://adamrosenfield.com/blog/2010/04/23/dumping-core/

关于c - 以编程方式打开核心/故障转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8144118/

相关文章:

c++ - 我如何在 C/C++ 中接收原始的第 2 层数据包?

c - 对 `yywrap` 的 undefined reference

c++ - 在gdb tui中打印utf 8符号

linux - 使用 wpa_supplicant 中的状态/事件通知获取连接过程错误的原因

c - 为什么在这两个测试用例中我的输出是错误的?

python - 为什么我的 python/numpy 示例比纯 C 实现更快?

c - fork () : Number of child processes created

C:关于通过使用超过当前 seek_set 的偏移量来使用 lseek 系统调用

c - 使用 struct utimbuf 更改文件访问时间

javascript - Red5 与 JavaScript 客户端聊天