How to generate a core file when a segment error occurs in Linux

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.