Current location - Quotes Website - Personality signature - How to turn on the switch of core dump file under linux
How to turn on the switch of core dump file under linux
Dumping files can facilitate us to check the location and context information of the crash when the program crashes. In this window, you need to write the corresponding code to generate the dump file. But now you can find the corresponding code online, download it and add it to your own project. It's much simpler under linux. As long as the corresponding switch is turned on, linux will automatically generate the corresponding core file when the program crashes. This file is similar to the dump file under window. Here are some simple steps: 1. Check whether the switch is currently on. Pass command: ulimit -c If the output is 0, it means it is not opened. If it is infinite, it has already been opened, so there is no need to open it again. 2. Open ulimit -c without restriction by command. Then through the step 1, you can monitor whether the opening is successful. 3. if you want to cancel, it's simple: ulimit -c 0 will do. After being modified by the above command, it is usually only valid for the current session. The next time you log in, you still have to re-enter the above command, so it is very troublesome. We can make the system open automatically every time by modifying the /etc/profile file. The steps are as follows: 1. First open the /etc/profile file, and you can usually find this sentence in the file: ulimit-s-c 0/dev/null 2&; 1. Well, according to the above example, we just need to change that 0 to unlimited. Then save and exit. 2. Make the current setting take effect through source /etc/profile. 3. Check whether it has been opened through ulimit -c C, in fact, not only this command can be added to the /etc/profile file, but also some other commands that we need to take effect every time we log in, because linux will load this file when we log in. Such as the setting of some environment variables. There is another method that can be set by modifying the file /etc /etc/security/limits.conf, which has never been tried before and is also seen on the Internet. But both of the above can be done! Finally, talk about the location where the coredump 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 pattern of coredump file name is saved in /proc/sys/kernel/core_pattern, and the default value is core. You can change the location of the coredump file (if you want to generate it in the /tmp/cores directory) by the following command. After echo "/tmp/cores/core"/proc/sys/kernel/core _ pattern is set, we can do a test, write a program and generate an exception. Then you will see a core* file in the current directory. Then we can go to gdb core. * Program debugging.