原始的

/proc/sys/kernel/core_pattern :
|/usr/share/apport/apport %p %s %c

修改 core dump 文件生成规则

必需切换到root才用权限修改 core_pattern 文件:

$ su
password: (这里输入root密码)

下面修改改 core_pattern 文件

# echo core-%e-%p-%t > /proc/sys/kernel/core_pattern

退出root

# exit

修改coredump文件限制

在 /etc/profile 文件中添加一行:

ulimit -c unlimited > /dev/null 2>&1

然后使修改生效:

$ su
password: (这里输入root密码)
# source /etc/profile
# exit

Configure it forever

The changes done before are only applicable until the next reboot. In order to make the change in all future reboots, you will need to add the following in “/etc/sysctl.conf“:

Own core file pattern...

kernel.core_pattern=/tmp/cores/core.%e.%p.%h.%t

sysctl.conf is the file controlling every configuration under /proc/sys

That should cause your custom pattern to be loaded on boot. You should be able to test it without rebooting by running sudo sysctl --system

man core 可以查看一些帮助

在 /etc/security/limits.conf 也可以修改 coredump 文件大小, 不过我没试过, 下面是 资料:

How do I enable core dumps for everybody Overview

In most Linux Distributions core file creation is disabled by default for a normal user. However, it can be necessary to enable this feature for an application (e.g. Oracle). For example, if you encounter an ORA-7445 error in Oracle, then it must be possible to write a core file for the user 玱racle?.

To enable writing core files you use the ulimit command, it controls the resources available to a process started by the shell, on systems that allow such control.

If you try to enable writing core files, usually you run in the following problem. Normally SSH is used to logon to the server.

ssh oracle@ora-server
$ ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Now, try (not as user root) to change the core file size to unlimited

$ ulimit -c unlimited
-bash: ulimit: core file size: cannot modify limit: Operation not permitted

Solution

    Check Environment for ulimit

    The first step is to check, that you don't set ulimit -c 0 in any shell

configuration files for this user, for example in $HOME/.bash_profile or $HOME/.bashrc. Uncomment it if you have such an entry.

    #
    # Do not produce core dumps
    #
    # ulimit -c 0

    Globally enable Core Dumps

    This must be done as user root, usually in /etc/security/limits.conf

    # /etc/security/limits.conf
    #
    # Each line describes a limit for a user in the form:
    #
    # <domain> <type> <item> <value>
    #
    *  soft  core  unlimited
     
    Logoff and Logon again and set ulimit

    ssh oracle@ora-server
    $ ulimit -c
    0

    Try to set the limit as user root first

    su -
    ulimit -c unlimited
    ulimit -c
    unlimited

    Now you can set ulimit also for user oracle

    su - oracle
    ulimit -c unlimited
    ulimit -c
    unlimited

Perhaps the last step number 3 is not necessary, but we have figured out,

that this is the way which always work. The core file size limitation is usually also set in different configuration files. If you want to enable cores, you can uncomment them.

In /etc/profile (Redhat)

# No core files by default
# ulimit -S -c 0 > /dev/null 2>&1

In /etc/init.d/functions (Redhat)

# make sure it doesn't core dump anywhere unless requested
# ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0} >/dev/null 2>&1

Now, from this current shell you can generate the core, so check ulimit

before.

$ ulimit -a

core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited