实验平台:
[root@myhost core]# uname -a
Linux myhost 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux
core文件一般生成格式为core.pid
其中,pid为产生core文件的进程ID
1. 查看当前core文件大小限制 ulimit -c
[root@myhost core]# ulimit -c
0
Linux中core文件大小默认是0,即不产生core文件
2. 设置core文件大小限制 ulimit -c size
单位是KB
[root@myhost core]# ulimit -c 1024
[root@myhost core]# ulimit -c
1024
若生成core文件大小超过设置的core文件大小限制,则超过部分将会被裁剪。 若设
置ulimit -c unlimited,则core文件大小无限制.
3.编写产生core文件程序
#include<stdio.h>
#include<unistd.h>
static void test(void);
int main(void)
{
printf("process ID: %d/n", getpid());
test();
return 0;
}
static void test(void)
{
int a=10/0;
printf("%d/n", a);
}
4./生成core文件
[root@myhost core]# gcc -g core.c -o core
core.c: In function ‘test’:
core.c:14: warning: division by zero
[root@myhost core]# ./core
process ID: 15729
Floating point exception (core dumped)
[root@myhost core]# ls
core core.15729 core.c
5. 调试core文件
[root@myhost core]# gdb ./core
GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb) core-file core.15729
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 `./core'.
Program terminated with signal 8, Arithmetic exception.
[New process 15729]
#0 0x08048404 in test () at core.c:14
14 int a=10/0;
(gdb)