Article Title: how to generate a core file when a segment error occurs in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In Linux, C programs often cause segment fault (segment error) due to memory access errors and other reasons. If the system core dump function is enabled, then there will be a memory image dumped to the hard disk, and then you can use gdb to analyze the core file to restore the stack situation when the system has a segment error. This is helpful for discovering program bugs.
You can use ulimit-a to view the size limit of system core files. You can use ulimit-c [kbytes] to set the size of core files that can be generated by the system, for example
Ulimit-c 0 does not generate core files
Ulimit-c 100 sets the core file size to 100 KB
Ulimit-c unlimited does not limit the core File Size
First look at a program that will cause a segment error:
# Include
Int main ()
{
Char * ptr = "linuxers.cn ";
* Ptr = 0;
}
The result is as follows:
[Leconte @ localhost test] $ gcc-g-o test a. c
[Leconte @ localhost test] $./test
Segment Error
At this time, the core file is not generated. Next, use ulimit-c to set the core file size to unlimited, and then run the./test program. The result is as follows:
[Leconte @ localhost ~] $ Ulimit-
Core file size (blocks,-c) 0
.........
[Leconte @ localhost test] $ ulimit-c unlimited
[Leconte @ localhost test] $ ulimit-
Core file size (blocks,-c) unlimited
..............
[1] [2] Next page