When developing a program using C/C ++, generating a coredump file when the program crash is used is very helpful for debugging the program. In RedHatLinux, The coredump file is not generated by default, because the/etc/profile file has such a line of ulimit-S-c0 & gt;/dev/null2 & gt; & amp; 1. How to enable coredump? The simplest way is ~ /. Bash_profil
When developing a program using C/C ++, it is helpful to debug the program to generate a core dump file when the program crash. In RedHat Linux, core dump files are not generated by default, because such a line exists in the/etc/profile file.
Ulimit-S-c 0>/dev/null 2> & 1
How to enable core dump? The simplest way is ~ /. Add ulimit-S-c unlimited>/dev/null 2> & 1 to the bash_profile. This allows the current user to generate a core dump file with no size limit. In addition, there are two ways to generate core dump through system-level modifications.
The first method is to modify/etc/profile and change the line of ulimit
Ulimit-S-c unlimited>/dev/null 2> & 1
In this way, the system allows all users to generate core dump files with no size limit. The advantage of this is that the system does not need to be restarted. The disadvantage is that it cannot be controlled and only allows some users to generate core dump files.
The second method is to modify the/etc/security/limits. conf file. Many system limits can be changed by modifying this file, such as the maximum number of sub-processes and the maximum number of opened files. This file has a detailed description of how to modify the file. If you want to open core dump for all users, you can add a line
* Soft core 0
If you only want to enable core dump for some users or user groups, you can add
User soft core 0 or @ group soft core 0
Note: If you open the core dump by modifying the/etc/security/limits. conf file, you need to comment out the ulmit line in/etc/profile.
# Ulimit-S-c 0>/dev/null 2> & 1
The advantage of this modification is that the core dump file can be opened for a specific user or a specific group. The disadvantage is that the system needs to be restarted.
Finally, let's take a look at the location where the core dump file is generated. The default location is in the same directory as the executable program. The file name is core. ***, where *** is a number. The mode of the core dump file name is saved in/proc/sys/kernel/core_pattern. The default value is core. Run the following command to change the location of the core dump file (for example, to be generated in the/tmp/cores directory)
Echo "/tmp/cores/core">/proc/sys/kernel/core_pattern