Changing location of core dump
Yes, it is. You can change /proc/sys/kernel/core_pattern
to define the pathname used to generate the corefile. For more, see man core
example:
echo '/tmp/core_%e.%p' | sudo tee /proc/sys/kernel/core_pattern # `tee' instead of > so that
# opening happens in the
# elevated process
would cause all future core dumps to be generated in /tmp
and be named core_[program].[pid]
How to change the path of Oracle JVM core dump file?
The answer depends on your Java version and the OS platform.
For Java 8 on Linux, the location is hard-wired to the current directory.
For Java 11 and Java 17 on Linux, the JVM uses the Linux "/proc/sys/kernel/core_pattern" mechanism described in Changing location of core dump and other places.
On BSD (e.g. Darwin), the location is Java version dependent: either "/core" (hard wired) or a location provided by the OS kernel.
On AIX and Windows it seems to use the current directory in all Java versions.
And so on.
(The above is from looking at the OpenJDK source code for Java 8, 11 and 17. Note that the relevant code changed substantially between Java 8 and 11.)
How to change the path of, or disable python's core dump?
You can use shell command ulimit
to control it:
ulimit -c 0 # Disable core file creation
Without the value, it will print current limit (the maximum size of core file will be created):
ulimit -c
Core dumped, but core file is not in the current directory?
Read /usr/src/linux/Documentation/sysctl/kernel.txt.
core_pattern is used to specify a core dumpfile pattern name.
- If the first character of the pattern is a '|', the kernel will treat
the rest of the pattern as a command to run. The core dump will be
written to the standard input of that program instead of to a file.
Instead of writing the core dump to disk, your system is configured to send it to the abrt
(meaning: Automated Bug Reporting Tool, not "abort") program instead. Automated Bug Reporting Tool is possibly not as documented as it should be...
In any case, the quick answer is that you should be able to find your core file in /var/cache/abrt
, where abrt
stores it after being invoked. Similarly, other systems using Apport may squirrel away cores in /var/crash
, and so on.
Change application core dump directory with c program
You can change core dump pattern globally through /proc/sys/kernel/core_pattern
.
But if you only want to change the core dump directory of one process, you can do what Apache web server does - register a signal handler that changes the current directory right before core dumping:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/resource.h>
#define COREDUMP_DIR "/tmp"
static void sig_coredump (int sig)
{
struct sigaction sa;
// Change to the directory we want the core to be dumped
chdir (COREDUMP_DIR);
// Clear the signal handler for the signal
memset (&sa, 0, sizeof (sa));
sa.sa_handler = SIG_DFL;
sigemptyset (&sa.sa_mask);
sigaction (sig, &sa, NULL);
// Send the signal again
raise (sig);
}
int main (int argc, char **argv)
{
struct sigaction sa;
// Set up the signal handler for all signals that
// can cause the core dump
memset (&sa, 0, sizeof (sa));
sa.sa_handler = sig_coredump;
sigemptyset (&sa.sa_mask);
sigaction (SIGSEGV, &sa, NULL);
sigaction (SIGBUS, &sa, NULL);
sigaction (SIGABRT, &sa, NULL);
sigaction (SIGILL, &sa, NULL);
sigaction (SIGFPE, &sa, NULL);
// Enable core dump
struct rlimit core_limit;
core_limit.rlim_cur = RLIM_INFINITY;
core_limit.rlim_max = RLIM_INFINITY;
if (setrlimit (RLIMIT_CORE, &core_limit) == -1) {
perror ("setrlimit");
}
// Trigger core dump
raise (SIGSEGV);
return 0;
}
Note that as this relies on the crashing application itself setting up and being able to run the signal handler, it can't be 100% bullet-proof - signal may be delivered before signal handler is set up or signal handling itself may get corrupted.
Related Topics
Can't Change Tomcat 7 Heap Size
How to Get All Parent Processes and All Subprocesses with 'Pstree'
Finding Human-Readable Files on Unix
How to Ignore Some Differences in Diff Command
Failing to Connect to Remote Mongodb Server
Which Linux Distribution Should I Use as a Xen Host
What Does 'Set -O Errtrace' Do in a Shell Script
Linux - Bash - Get $Releasever and $Basearch Values
Wget-Like Bittorrent Client or Library
Find the Ip Address of the Client in an Ssh Session
Bluetooth Low Energy: Use Bluez Stack as a Peripheral (With Custom Services and Characteristics)
A Running Bash Script Is Hung Somewhere. How to Find Out What Line It Is On
Grep Files Based on Time Stamp
Parallel Make: Set -J8 as The Default Option
Gvim Redraw Issues with Virtual Box and Windows 7 Host