The C program under Linux often causes a segment fault due to memory access errors, etc., if the system core dump function is Opened, then there will be a memory image dumped to the hard disk, then you can use gdb to analyze the core file, restore the stack situation when the system has a segmentation error. This is very helpful for us to find bugs.
Use ulimit -a to view the size limit of the system core file; use ulimit -c [kbytes] to set the size of the core file allowed to be generated by the system, for example
ulimit -c 0 does not generate core file
ulimit - c 100 Set the core file to a maximum of 100k
ulimit -c unlimited Do not limit the size of the core file
Look at a program that will cause a segmentation error:
#include
int main()
{ < Br> char *ptr="linuxers.cn";
*ptr=0;
}
The result of compiling and running is as follows:
[leconte@localhost test]$ gcc -g -o test Ac
[leconte@localhost test]$ ./test
Segment Error
There is no core file generated at this time, then use ulimit -c to set the core file size to unlimited, then execute the ./test program. The result is as follows:
[leconte@localhost ~]$ ulimit -a
core file size (blocks, -c) 0
[leconte@localhost test]$ ulimit -c unlimited
[leconte@ Localhost test]$ ulimit -a
core file size (blocks, -c) unlimited
[leconte@localhost test]$ ./test
segment dump (core dumped)
[leconte@loc Alhost test]$ ls -al core.*
-rw------- 1 leconte leconte 139264 01-06 22:31 core.2065
Visible core file has been generated, then gdb analysis , see the stack situation:
[leconte@localhost test]$ gdb ./test core.2065
GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 Free Software Foundation, Inc. < Br> License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying" Br> and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
warning: exec file is newer than core file.
warning: Can't read pathname for load map: Input/output error.
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./test'.
Program term Inated with signal 11, Segmentation fault.
[New process 2065]
#0 0x0804836f in main () at ac:6
6 *ptr=0;
It is clear from the above output The segmentation error occurred on line 6 of ac and the problem has been clearly located.
Many system default core file sizes are 0, we can specify the core file size by adding the ulimit -c command in the shell startup script /etc/bashrc or ~/.bashrc, etc., to ensure that the core file can generate.
In addition, you can also set the file name template of the core file in /proc/sys/kernel/core_pattern. For details, please refer to the official man page of the core.
Get the NIC traffic through the 3rd party tool, this must be very clear. In fact, the effect can be
Linux 2.6 device drivers are built on the basis of the device model, therefore, to write device driv
Under Linux, the IDE device is named after hd. Generally, there are two IDE interf
Cant write data on the hard disk of Linux or UNIX-like systems? Want to solve the problem of disk co
LINUX device driver - race, blocking, reentrant code
Unix network programming entry basic tutorial
Linux simple backup script tutorial
Take you to know the password "breaking" software under Linux
Linux operating system startup process detailed
Threaded process classic linux article
Set disk quotas for Linux MySQL databases
Squid log file is too large, how to deal with it?
Linux auto-execute crontab study notes
Using Yum to manage local software packages
Linux/Unix operating system is in the desktop control of the intranet
Win7/8 how to view the computer configuration win10 computer hardware configuration view method
Windows10 system U disk boot disk production tutorial
Windows7 accidentally deleted system built-in hidden partition caused system crash
Easy to solve Win8 application installation and uninstallation issues
How to cleverly uninstall Win8's own input method
Windows 7 tips: shielded window smart arrangement
Use optimized drivers to improve the performance of Windows 8 system
How does Win10 come with Directx version?
XP system can not open the device manager prompt "Windows can not find mmc.exe" What should I do?
Win10 can not find the group policy editor how to do win10 group strategy can not open the solution