How Do I run ulimit -c unlimited automatically

断了今生、忘了曾经 提交于 2019-12-11 03:53:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!