How to open the core dump file switch under Linux

Source: Internet
Author: User

The dump file allows us to view the crash of the program and contextual information when the program crash. Under window, to be able to generate a dump file, you need to write the appropriate code yourself. But now the online can find the corresponding code, as long as it downloaded and then added to their project to go, you can!

It's a lot simpler under Linux. As soon as you turn on the switch, Linux automatically generates the corresponding core file when the program crash. This file is similar to the dump file under window.
Here are some simple steps:
1. See if this switch is currently turned on
by command: ulimit-c if the output is 0, the representation is not open. If the unlimited is already open, there is no need to open it.
2. Open by command
Ulimit-c Unlimited. Then through step 1, you can monitor whether the open is successful.
3. If you want to cancel, it's easy: ulimit-c 0.
After the above command modification, it is generally only for the current session to work, when you re-login next time, or to re-enter the above command, so it is troublesome. We can make the system open automatically each time by modifying the/etc/profile file.
The steps are as follows:
1. Open the/etc/profile file first
It is generally possible to find this sentence in the file: Ulimit-s-C 0 >/dev/null 2>&1.ok, according to the above example, we just have to change that 0 to unlimited is OK. Then save the exit.
2. Make the current setting effective by Source/etc/profile.
3. Check to see if the ulimit-c is turned on.
In fact, not only this command can be added to the/etc/profile file, and some of the other we need each login to take effect can be added to this file, because Linux will load this file when logging in. such as the setting of some environment variables.
There is also a way to modify the/etc/security/limits.conf file to set up, this method has not been tried, but also online to see. But the above two can be!
Finally, the location where the core dump file is generated, the default location is in the same directory as the executable program, and 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, and the default value is core. You can change the location of the core dump file by using the following command (if you want to build into the/tmp/cores directory)
echo "/tmp/cores/core" >/proc/sys/kernel/core_pattern

After setting up, we can do a test, write a program, produce an exception. Then you see that the current directory has a core* file. Then we can
GDB Core. * The program is debugged.

How to open the core dump file switch under Linux

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.