问题
I am trying to provide support for coredump file generation from my rootfs ,I have modified /etc/limits file with "ulimit -c unlimited" command and "* hard core -1" ,Now when I give kill -6 $$ ,expecting core file generation but to get this core file have to run ulimit -c unlimited explicitly .
But I want it to happen automatically , no need to run ulimit -c unlimited it again in shell.
Can anybody tell me what changes I have to make for the same to happen
回答1:
From a program you can use setrlimit(RLIMIT_CORE, ...)
to set the core file's maximum size. To specifiy an infinite size pass RLIM_INFINITY
.
For details on this please read here: http://manpages.debian.net/cgi-bin/man.cgi?query=getrlimit&sektion=2
Using the sysctl
command you can do
sysctl kernel.core_pattern=/var/core/core.%p
to have the kernel create cores named core.<pid>
in /var/core
.
Adding kernel.core_pattern=/var/core/core.%p
to /etc/sysctl.conf
makes it permanent. (run sysctl -p
to process your changes to /etc/sysctl.conf
)
Besides %p
(for the process id) there are other placeholders as follows (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/how-do-i-run-ulimit-c-unlimited-automatically