如何自动运行ulimit -c unlimited

Ami*_*mar 2 c linux coredump rootfs ulimit

我试图从我的rootfs提供对coredump文件生成的支持,我已经用"ulimit -c unlimited"命令和"*hard core -1"修改了/ etc/limits文件,现在当我给kill -6 $$时,期待核心文件生成,但要获得此核心文件必须显式运行ulimit -c unlimited.

但是我想让它自动发生,不需要在shell中再次运行ulimit -c unlimited.

任何人都可以告诉我,为了发生同样的事情,我必须做出哪些改变

alk*_*alk 6

从程序中,您可以使用它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
Run Code Online (Sandbox Code Playgroud)

有内核创建一个名为内核core.<pid>/var/core.

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

此外%p(对于进程ID)还有其他占位符如下(取自此处):

%%  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)
Run Code Online (Sandbox Code Playgroud)