我如何自动运行ulimit -c无限?

时间:2021-09-15 09:18:40

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 .

我试图为coredump提供支持文件生成rootfs,我有修改/etc/limits文件“ulimit - c无限”命令和“*核心1”,现在当我给杀死6 $ $,预计核心文件生成但得到这个核心文件必须明确运行ulimit - c无限。

But I want it to happen automatically , no need to run ulimit -c unlimited it again in shell.

但是我希望它自动发生,不需要运行ulimit -c,在shell中再次无限制。

Can anybody tell me what changes I have to make for the same to happen

谁能告诉我,为了同样的事情,我必须做出哪些改变?

1 个解决方案

#1


5  

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.

通过一个程序,您可以使用setrlimit(RLIMIT_CORE,…)来设置核心文件的最大大小。对于一个无穷大的大小通过rlim_无穷大。

For details on this please read here: http://manpages.debian.net/cgi-bin/man.cgi?query=getrlimit&sektion=2

有关这一点的详细信息请在这里阅读:http://manpages.debian.net/cgi-bin/man.cgi?query=getrlimit&sektion=2。


Using the sysctl command you can do

您可以使用sysctl命令。

sysctl kernel.core_pattern=/var/core/core.%p

to have the kernel create cores named core.<pid> in /var/core.

要让内核创建名为core的内核。在/var/core. < pid >

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)

添加kernel.core_pattern = / var /核心/核心。% p /etc/sysctl.conf让它永久。(运行sysctl -p,以处理对/etc/sysctl.conf的更改)

Besides %p (for the process id) there are other placeholders as follows (taken from here):

除了%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)

#1


5  

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.

通过一个程序,您可以使用setrlimit(RLIMIT_CORE,…)来设置核心文件的最大大小。对于一个无穷大的大小通过rlim_无穷大。

For details on this please read here: http://manpages.debian.net/cgi-bin/man.cgi?query=getrlimit&sektion=2

有关这一点的详细信息请在这里阅读:http://manpages.debian.net/cgi-bin/man.cgi?query=getrlimit&sektion=2。


Using the sysctl command you can do

您可以使用sysctl命令。

sysctl kernel.core_pattern=/var/core/core.%p

to have the kernel create cores named core.<pid> in /var/core.

要让内核创建名为core的内核。在/var/core. < pid >

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)

添加kernel.core_pattern = / var /核心/核心。% p /etc/sysctl.conf让它永久。(运行sysctl -p,以处理对/etc/sysctl.conf的更改)

Besides %p (for the process id) there are other placeholders as follows (taken from here):

除了%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)