我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各种异常或者bug导致在运行过程中异常退出或者中止,并且在满足一定条件下(这里为什么说需要满足一定的条件呢?下面会分析)会产生一个叫做core的文件。
通常情况下,core文件会包含了程序运行时的内存,寄存器状态,堆栈指针,内存管理信息还有各种函数调用堆栈信息等,我们可以理解为是程序工作当前状态存储生成第一个文件,许多的程序出错的时候都会产生一个core文件,通过工具分析这个文件,我们可以定位到程序异常退出的时候对应的堆栈调用等信息,找出问题所在并进行及时解决。
$ ulimit -a
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) 8192
-c: core file size (blocks) 0
-m: resident set size (kbytes) unlimited
-u: processes 14014
-n: file descriptors 65535
-l: locked-in-memory size (kbytes) 64
-v: address space (kbytes) unlimited
-x: file locks unlimited
-i: pending signals 14014
-q: bytes in POSIX msg queues 819200
-e: max nice 0
-r: max rt priority 0
-N 15: unlimited
core file size = 0,说明core文件没有开启
如果core没有开启,则不会生成core文件
使用ulimit -c [kbytes]
可以设置系统允许生成的core文件大小
ulimit -c 0 不产生core文件
ulimit -c 500 设置core文件最大为500k
ulimit -c unlimited 不限制core文件大小
$ ulimit -c unlimited
#查看配置
$ ulimit -a
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) 8192
-c: core file size (blocks) unlimited
-m: resident set size (kbytes) unlimited
-u: processes 14014
-n: file descriptors 65535
-l: locked-in-memory size (kbytes) 64
-v: address space (kbytes) unlimited
-x: file locks unlimited
-i: pending signals 14014
-q: bytes in POSIX msg queues 819200
-e: max nice 0
-r: max rt priority 0
-N 15: unlimited
修改/etc/profile文件,添加参数
$ echo 'ulimit -c unlimited' >> /etc/profile
$ source /etc/profile
$ cat /proc/sys/kernel/core_pattern /dmdata/core/core-%e-%p-%s
core文件统一生成指定到/dmdata/core目录下,产生的文件名为core-命令名-pid-信号
$ vi /etc/sysctl.conf
kernel.core_pattern =/dmdata/core/core-%e-%p-%s
$ sysctl -p #生效
core文件名参数列表
参数 | 说明 |
---|---|
%p | 添加pid(进程id) |
%u | 添加当前uid(用户id) |
%g | 添加当前gid(用户组id) |
%s | 添加导致产生core的信号 |
%t | 添加core文件生成时的unix时间 |
%h | 添加主机名 |
%e | 添加导致产生core的命令名 |
CREATE TABLE T(ID INT);
INSERT INTO T SELECT LEVEL FROM DUAL CONNECT BY LEVEL <10000500;
$ ps -ef|grep dmdba
dmdba 2837894 1 0 14:49 ? 00:00:01 /home/dmdba/dmdbms/bin/dmap
dmdba 2848517 1 0 20:49 ? 00:00:05 /home/dmdba/dmdbms/bin/dmserver path=/dmdata/data/DAMENG/dm.ini -noconsole
$ kill -11 2848517
# 生成了core文件
$ ls /dmdata/core/
core-dmserver-2848517-8
命令 | 说明 |
---|---|
bt | 查看当前线程的栈信息 |
thread apply all bt | 查看所有线程堆栈,通常会由此查看是否有自己实现的类或者so库。一般会把所有线程的详细栈信息输出到一个文件里面如thread_info.txt |
thread id | 将线程编号为 id 的线程设置为当前线程。 |
info threads [id…] | 可以查看当前调试环境下存在的线程数以及各线程的具体信息,也可以通过指定线程的编号查看某个线程的具体信息。 |
$ gdb 产生core的命令名 core文件
$ gdb dmserver core-dmserver-2848517-8
GNU gdb (GDB) Red Hat Enterprise Linux 9.2-7.1.0.4.al8
Copyright (C) 2020 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 "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from dmserver...
Reading symbols from /home/dmdba/dmdbms/bin/dmserver_s.debug...
......
(gdb) set logging file core_2848517.txt
(gdb) set logging on
Copying output to core_2848517.txt.
Copying debug output to core_2848517.txt.
(gdb) thread apply all bt Thread 86 (Thread 0x7ff2e63e5640 (LWP 2848563)): ......
(gdb) set logging off
Done logging to core_2848517.txt.
$ dmrdc sfile=/dmdata/core/core-dmserver-2848517-8 dfile=/dmdata/core/core_sql dmrdc V8 Analysing: 0/3096002560 Analysing: 31457268/3096002560 Analysing: 62914536/3096002560 ...... Analysing: 3082812264/3096002560 6.116 s $ ls -l /dmdata/core total 676856 -rw-r--r-- 1 dmdba dinstall 62610 Mar 10 22:18 core_2848517.txt -rw------- 1 dmdba dinstall 3096002560 Mar 10 21:59 core-dmserver-2848517-8 -rw-r--r-- 1 dmdba dinstall 102 Mar 10 22:35 core_sql
$ cat core_sql
!#%&*^$@[2852035]:INSERT INTO T SELECT LEVEL FROM DUAL CONNECT BY LEVEL <10000500;
结合dmrdc的结果对应的SQL语句(从dmrdc的结果中找对应的2852035线程号,去
core_2848517.txt
文件中查找线程2852035的堆栈信息进行分析。)
文章
阅读量
获赞