How to collect a coredump of a running process without killing the process or without restarting an application?
Environment
- Red Hat Enterprise Linux
Issue
-
How to obtain a core file without restarting an application?
-
How an application core can be generated when a process is not crashing?
-
I want to collect a coredump of a running process without killing the process
-
I use
gcoreto collect the coredump but buildids and libraries are not available through executingeu-unstripcommand# gcore <pid> [...] Saved corefile core.<pid> # eu-unstrip -n --core=core.<pid> | grep -c "/lib64/" 0
Resolution
-
The
gcorecommand can be used to obtain the core file without causing the application to abort using the following procedure:-
Ensure that the
gdbpackage is installed. -
Run the application.
-
Execute the gcore command to generate a core file (like core.pid) from the application in the current directory:
# gcore (pid of the process)
-
-
Some old versions of
gcorecommands ingdbpackage generates coredump files which are not suitable for analyzing on remote systems. Use following packages and commands.- RHEL 7:
devtoolset-9-gdbfromrhel-server-rhscl-7-rpmsrepository, command is/opt/rh/devtoolset-9/root/usr/bin/gcore - RHEL 8:
gcc-toolset-9-gdb, command is/opt/rh/gcc-toolset-9/root/usr/bin/gcore - RHEL 9:
gcc-toolset-13-gdb, command is/opt/rh/gcc-toolset-13/root/usr/bin/gcore
- RHEL 7:
-
The core file will be outputted to the present working directory.
On RHEL 7
Use the gcore utility shipped with devtoolset-9-gdb, the package delivered with Red Hat Software Collections.
If this is not possible, then follow the instructions in section Fallback in case only standard gcore utility is available.
-
Enable the Red Hat Software Collections
# subscription-manager repos --enable rhel-server-rhscl-7-rpmsFor details, please refer to How to use Red Hat Software Collections (RHSCL) or Red Hat Developer Toolset (DTS)?.
-
Install the
devtoolset-9-gdbpackage# yum -y install devtoolset-9-gdb -
Should the install fail with a missing dependency as seen below:
Error: Package: devtoolset-9-gdb-8.3-3.el7.x86_64 (rhel-server-rhscl-7-rpms) Requires: libsource-highlight.so.4()(64bit)Enable the
rhel-7-server-optional-rpmsrepository so thatsource-highlightRPM can be installed:# subscription-manager repos --enable rhel-7-server-optional-rpmsAnd repeat step 2 again.
-
Produce the coredump using
gcore# /opt/rh/devtoolset-9/root/usr/bin/gcore <pid> [...] Saved corefile core.<pid> -
Verify that
eu-unstripshows now the buildids and libraries# yum -y install elfutils # eu-unstrip -n --core=core.<pid> | grep -c "/lib64/" 19
On RHEL 8
Use the gcore utility shipped with gcc-toolset-9-gdb, the package delivered with AppStream repository.
-
Install the
gcc-toolset-9-gdbpackage# yum -y install gcc-toolset-9-gdb -
Produce the coredump using
gcore# /opt/rh/gcc-toolset-9/root/usr/bin/gcore <pid> [...] Saved corefile core.<pid>Note: if you get a Operation not permitted error message, verify that
fapolicydservice is enabled, and stop it temporarily (this issue is tracked by This content is not included.BZ 1817969 - Cannot execute gcore from gcc-toolset-9 when fapolicyd is enabled):# /opt/rh/gcc-toolset-9/root/usr/bin/gcore <pid> /opt/rh/gcc-toolset-9/root/usr/bin/gcore: line 100: /opt/rh/gcc-toolset-9/root/usr/bin/gdb: Operation not permitted # systemctl is-active fapolicyd active # systemctl stop fapolicyd # /opt/rh/gcc-toolset-9/root/usr/bin/gcore <pid> [...] Saved corefile core.<pid> # systemctl start fapolicyd -
Verify that
eu-unstripshows now the buildids and libraries# yum -y install elfutils # eu-unstrip -n --core=core.<pid> | grep -c "/lib64/" 19
Fallback in case only standard gcore utility is available
-
Collect the coredump using the standard utility
# yum -y install gdb # gcore <pid> -
Collect the DSO list
# yum -y install abrt-addon-ccpp # abrt-action-list-dsos -m /proc/<pid>/maps -o dso_list
On RHEL 9
Use the gcore utility shipped with gcc-toolset-13-gdb, the package delivered with AppStream repository.
-
Install the
gcc-toolset-13-gdbpackage# yum -y install gcc-toolset-13-gdb -
Produce the coredump using
gcore# /opt/rh/gcc-toolset-13/root/usr/bin/gcore <pid> [...] Saved corefile core.<pid>
Note :
-
The
gcorecommand runsgdband attaches to the process, causing the process to enterTstatus. However, the process should try to continue to run after gdb finishes collecting a core. -
One point to remember is that with
gcorewe can't get a coredump of a kernel process. Becausekernelprocesses are immune to system call tracing,ptracewhich thegcorecommand uses. When we issue agcoreto a pid, we are usingPTRACE_ATTACH. When a parent process traces a child process, it usesPTRACE_TRACEME. See the man page ofptracefor more details.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.