How to generate a core dump file under Linux (fix segment fault segment error)

Source: Internet
Author: User

C programs under Linux often cause segment fault (segment error) due to memory access, and if the function of core dump is open, a file called core will be generated when running our executable program. We can then use GDB to tune the core file to restore the stack where the error occurred, which is very helpful for us to debug the bug.

1. Use ulimit-a to see the size limit of the current system core file;

Use Ulimit-c [Kbytes] To set the size of the core file that the system allows to generate.

Such as:

ULIMIT-C 0---Do not produce core files

ULIMIT-C---Set core file to 200k Max

ULIMIT-C Unlimited---Unlimited core file size

2. Let's write a procedure that will cause a section error.

  

The results of the compilation run are as follows:

  

Now look at our current file path and there is no core file generated.

3. Perform ulimit-a to view current system settings:

  

At this point we see that the current system core file size is 0, which means that no core files are generated.

Now we execute a command like this, without limiting the size of the generated core file.

  

Then we run our program and the visible core file is generated:

  

Finally, GDB is used to analyze the program and see the stack situation:

  

It is clear from the above output that the segment error appears on line 6th of testcore.c, and the problem is already fixed.

Many system default generated core file size is 0, like this to set the core file size, only valid in the current session, if the shutdown terminal restarts, then you need to enter the above command.

4. If you want to set the permanent effect, you can modify the/etc/security/limits.conf file, find * Soft core 0, modified to * soft core unlimited save, so every time you start to read this configuration file.

  

If you encounter the above situation, open limits.conf warning This is a read-only file, you can use the chmod command to modify the file permissions, add Write permissions.

Http://www.cnblogs.com/jiangson/p/5956674.html

How to generate a core dump file under Linux (fix segment fault segment error)

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.