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, the core dump file is not generated by default, because the/etc/profile file contains such a line of 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 row ulimit to 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 enable 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 that if you modify/etc/security/limits. open the conf file core dump, you also 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 it can be applied to a specific user or a specific group. open the core dump file, 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 the/tmp/cores directory) echo "/tmp/cores/core">/proc/sys/kernel/core_pattern