【问题标题】:How Do I run ulimit -c unlimited automatically如何自动运行 ulimit -c unlimited
【发布时间】:2013-08-21 12:11:39
【问题描述】:

我正在尝试为从我的 rootfs 生成 coredump 文件提供支持,我已经使用“ulimit -c unlimited”命令和“* hard core -1”修改了 /etc/limits 文件,现在当我给 kill -6 $ $ ,期望生成核心文件,但要获取此核心文件必须显式运行 ulimit -c unlimited 。

但我希望它自动发生,无需在 shell 中再次运行 ulimit -c unlimited 它。

谁能告诉我我必须做些什么改变才能发生同样的事情

【问题讨论】:

  • 把它放在你的.profile 文件中?
  • 将该行添加到您的 shell 启动文件中,可能是 ~/.profile
  • 可能想阅读this。看起来你可以用一些关于如何设置你自己的配置文件的信息来做。
  • 由于给定的原因无法将其放入配置文件,如果我更改为配置文件,这只会对从登录 shell 启动的程序生效,对 systemd 启动的进程/服务无效。 /etc/limits 将是设置这些默认值的正确位置。这个原因已被告知
  • @Nobilis 您想对上述内容发表评论

标签: c linux coredump ulimit rootfs


【解决方案1】:

您可以在程序中使用setrlimit(RLIMIT_CORE, ...) 设置核心文件的最大大小。指定无限大小的 pass RLIM_INFINITY

有关详情,请在此处阅读:http://manpages.debian.net/cgi-bin/man.cgi?query=getrlimit&sektion=2


使用sysctl 命令可以做到

sysctl kernel.core_pattern=/var/core/core.%p

让内核在/var/core 中创建名为core.<pid> 的内核。

kernel.core_pattern=/var/core/core.%p 添加到/etc/sysctl.conf 使其永久化。 (运行sysctl -p 处理您对/etc/sysctl.conf 的更改)

除了%p(用于进程ID)还有其他占位符如下(taken from here):

%%  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, 1970-01-01 00:00:00 +0000 (UTC)
%h  hostname (same as nodename returned by uname(2))
%e  executable filename (without path prefix)
%E  pathname of executable, with slashes ('/') replaced by exclamation marks ('!').
%c  core  file  size soft resource limit of crashing process (since Linux 2.6.24)

【讨论】:

  • 谢谢@alk,我正在寻找类似的东西,所以我需要在我的 /etc/sysctl.conf 中指定 sysctl kernel.core_pattern=/var/cor/core.%p ??然后我真的需要显式运行 ulimit -c unlimited 吗??
  • @AmitSinghTomar: kernel.core_pattern 指定放置核心文件的位置以及如何命名。
  • 很好@alk,但它不能解决我的问题,Cav 我们在 /etc/limits 文件中设置核心文件的最大大小?
  • @AmitSinghTomar:您可能想在程序外使用setrlimit() 来确定核心文件的最大大小,正如我的回答所建议的那样。
  • 是的@alk,这就是我正在研究的内容。你知道它在 Linux 代码中的哪个位置设置。
猜你喜欢
  • 2017-07-19
  • 2012-10-26
  • 2013-03-28
  • 2020-10-04
  • 2019-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多