我正在尝试从rootfs提供对coredump文件生成的支持,我已经使用“ulimit -c unlimited”命令和“* hard core -1”修改了/etc/limits文件,现在当我给kill -6 $$时,期望核心文件生成,但要获取此核心文件,必须显式运行ulimit -c unlimited。
但是我希望它能够自动发生,而无需在 shell 中再次运行ulimit -c unlimited。
谁能告诉我要做出相同的改变
最佳答案
在程序中,您可以使用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
让内核在core.<pid>
中创建名为/var/core
的内核。在
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)
关于c - 我如何自动运行ulimit -c unlimited,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18357085/