我正在尝试提供从我的根文件生成核心转储文件的支持,我已经使用"ulimit -c ulimit“命令和"* hard core -1”修改了/etc/limits文件,现在当我给kill -6 $$时,期望核心文件生成,但为了让这个核心文件必须显式地运行ulimit -c unLimit.
但我希望它是自动发生的,不需要在shell中再次运行ulimit -c ulimit它。
有谁能告诉我我必须做些什么改变才能发生同样的事情吗?
发布于 2013-08-21 20:36:50
在程序中,您可以使用setrlimit(RLIMIT_CORE, ...)来设置核心文件的最大大小。若要指定无限大小的传递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)https://stackoverflow.com/questions/18357085
复制相似问题