本文介绍了我如何自动运行ulimit -c unlimited的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 .

但是我希望它自动发生,而无需在shell中再次运行ulimit -c unlimited.

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

推荐答案

在程序中,您可以使用setrlimit(RLIMIT_CORE, ...)设置核心文件的最大大小.要指定无限大小,请通过RLIM_INFINITY.

From a program you can use setrlimit(RLIMIT_CORE, ...) to set the core file's maximum size. To specify an infinite size pass RLIM_INFINITY.

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

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

您可以使用sysctl命令

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

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

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

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

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)

%p(用于进程ID)之外,还有其他占位符,如下所示(从此处获取):

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)

这篇关于我如何自动运行ulimit -c unlimited的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 06:40