I am currently using JDK8, in the 17.4.2 Collect Core Dumps on Linux, there is the following description:
By default, the core dump is created in the current working directory of the process and the name of the core dump file is core.pid, where pid is the process id of the crashed Java process.
But I want to change the path of core dump, is there any way to achieve this?
I use sysctl -wq kernel.core_pattern=/opt/shared/core_%e.%p
to set it, but it doesn't work for the JVM process.
I use kill -11 java_pid
to simulate this situation, but the core dump is generated in the JVM process working directory, not the directory I set.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f6249b4e4a5, pid=1, tid=0x00007f6249b3cb80
#
# JRE version: OpenJDK Runtime Environment (8.0_332-b09) (build 1.8.0_332-b09)
# Java VM: OpenJDK 64-Bit Server VM (25.332-b09 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libpthread.so.0+0xa4a5] __pthread_clockjoin_ex+0x235
#
# Core dump written. Default location: /opt/core or core.1
#
# An error report file with more information is saved as:
# /opt/shared/java_error.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
[error occurred during error reporting , id 0xb]
Answer: The path to core dump can only be modified by changing the process working directory.
// Get the default path to the core file
// Returns the length of the string
int os::get_core_path(char* buffer, size_t bufferSize) {
const char* p = get_current_directory(buffer, bufferSize);
if (p == NULL) {
assert(p != NULL, "failed to get current directory");
return 0;
}
return strlen(buffer);
}
Reference: jdk/os_linux.cpp at jdk8-b120 · openjdk/jdk · GitHub