方法1、
(1)先获取进程的PID
ps -aux | grep test
# ps -aux | grep test
root 6906 85.7 0.0 4212 356 pts/0 R+ 00:56 3:57 ./test
root 6978 0.0 0.0 112708 980 pts/1 R+ 01:01 0:00 grep --color=auto test
(2)直接使用gcore产生coredump文件
# gcore 6906
func_1 () at test.c:6
6 while (1);
Saved corefile core.6906
# ls
123 core.6819 core.6906 test test.c
[root@localhost ~/test/test_2]
方法2、
(1)获取进程PID号;
(2)使用gdb工具attach到进程上;
(3)使用gcore + coredump文件名,生成coredump文件;
(4)使用detach脱离进程;
(5)使用quit退出gdb。
# gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 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".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) attach 6906
Attaching to process 6906
Reading symbols from /root/test/test_2/test...done.
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
func_1 () at test.c:6
6 while (1);
Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7.x86_64
(gdb) gcore test_coredump
Saved corefile test_coredump
(gdb) detach
Detaching from program: /root/test/test_2/test, process 6906
(gdb) quit
[root@localhost ~/test/test_2]
方法3、
先fork创建一个子进程,子进程拥有和父进程一样的内存空间了,然后在子进程触发abort信号,让子进程进行core
dump。
https://www.cnblogs.com/youxin/p/8833877.html