1. 程式人生 > >how to set the core dump file location(and name)?

how to set the core dump file location(and name)?

1、如何長期開啟core dump功能?

        編輯 /etc/profile,在末尾加上命令:

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

        如果原來檔案中有ulimit的相關呼叫,則直接改那個呼叫。

2、core dump檔案的生成方式:

       可以修改 /etc/sysctl.conf 檔案,加入以下內容:

kernel.core_uses_pid = 1
kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t
fs.suid_dumpable = 2
 

相關解釋(英文):

    kernel.core_uses_pid = 1 - Appends the coring processes PID to the core file name.
    fs.suid_dumpable = 2 - Make sure you get core dumps for setuid programs.
    kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t - When the application terminates abnormally, a core file should appear in the /tmp. The kernel.core_pattern sysctl controls exact location of core file. You can define the core file name with the following template whih can contain % specifiers which are substituted by the following values when a core file is created:
        %% - A single % character
        %p - PID of dumped process
        %u - real UID of dumped process
        %g - real GID of dumped process
        %s - number of signal causing dump
        %t - time of dump (seconds since 0:00h, 1 Jan 1970)
        %h - hostname (same as ’nodename’ returned by uname(2))
        %e - executable filename