On a HotSpot JVM, what is an hs_err_pid<pid>.log file, when is one written, and where do you look for it?
answer
- the JVM process itself died
- fatal error handler, not a stack trace
- default name has the pid in it
- working directory, then temp directory
- -XX:ErrorFile moves it
basics
~20 sAn hs_err_pid<pid>.log file is the fatal error log HotSpot writes when the JVM process itself crashes, for example on a SIGSEGV in native code. It lands in the working directory by default, falls back to the temp directory, and -XX:ErrorFile moves it.
solid answer
~40 sIt is HotSpot's **fatal error log**: when the VM hits a fatal signal (`SIGSEGV`, `SIGBUS`, …) in its own or native code, an internal VM error, or a failed native allocation, its error handler writes a report before the process dies. An ordinary Java exception or an `OutOfMemoryError` thrown to Java code does **not** produce one, unless `-XX:+CrashOnOutOfMemoryError` is set. In JDK 25 the file defaults to `./hs_err_pid%p.log` in the process's working directory (`%p` becomes the pid); if that cannot be opened it tries the temp directory, and if that fails too it prints the report to standard output. `-XX:ErrorFile=/path/hs_err_pid%p.log` chooses the location, and `-XX:+ErrorFileToStdout` or `-XX:+ErrorFileToStderr` sends the whole report to a stream instead. The JVM also prints a short `#` banner to stdout that names the file it wrote.
go deeper
Know that hs_err files exist, that they mean the JVM process crashed rather than threw an exception, and where the default one goes.
Explain the lookup order (ErrorFile, working directory, temp directory, stdout) and the stdout banner that names the file, and set ErrorFile on a real service.
Treat the presence or absence of the file as evidence: no file after a death points away from a HotSpot crash and towards an external kill or an orderly exit.
Decide where every production JVM's crash log goes, so a crash in an ephemeral container is never unrecoverable, and how long the files are kept.
## What the file is A **fatal error log** (the `hs_err_pid<pid>.log` file) is the report HotSpot's error handler writes when the JVM can no longer continue as a process. It is not a Java stack trace. A Java exception, even an uncaught one, is an event inside a healthy runtime: the thread dies, the stack trace is printed, and the JVM may keep running. A fatal error means the runtime itself is broken, so the handler records as much as it can about the machine state and then aborts the process. The report exists because after a crash there is no live process left to attach a tool to. Whatever you will learn about the crash, you learn from this file and, if one was written, a core dump. ## When HotSpot writes one The error handler runs for three broad kinds of failure: - **A fatal signal** inside the process: `SIGSEGV` (an invalid memory access), `SIGBUS`, `SIGILL` or `SIGFPE`, whether it happened in a native library, in JIT-compiled code or in the VM's own C++ code. - **An internal VM error**: an assertion or `guarantee` inside HotSpot that failed. The header then reads `Internal Error` with a source file and line number instead of a signal name. - **A native allocation failure**: the VM could not `malloc` or `mmap` memory it needed. That report opens with `There is insufficient memory for the Java Runtime Environment to continue.` instead of the usual crash banner. What does **not** produce one: - an exception thrown and not caught by Java code; - an `OutOfMemoryError` thrown to Java code, unless the JVM runs with `-XX:+CrashOnOutOfMemoryError`, which turns the first one into a deliberate crash with an error log; - a process killed from outside with `SIGKILL`, which no handler can catch, so nothing is written at all. ## Where to look In the JDK 25 source the file name pattern defaults to `hs_err_pid%p.log`, with `%p` replaced by the process id. The handler tries locations in order: 1. the path given by `-XX:ErrorFile`, if one was set; 2. the default name in the process's **current working directory**; 3. the default name in the **temp directory** (normally `/tmp` on Linux); 4. if no file can be opened, it prints `# Can not save log file, dump to screen..` and writes the report to standard output. The JVM also prints a short summary, every line starting with `#`, to standard output, ending with: ```console # An error report file with more information is saved as: # /srv/app/hs_err_pid4127.log ``` That banner is the first thing to look for in the service's console output or container log: it tells you that this was a JVM crash and exactly where the full report went. ## Controlling the location | Option | Effect | |---|---| | `-XX:ErrorFile=/crash/hs_err_pid%p.log` | writes the report to that path, `%p` expanded to the pid | | `-XX:+ErrorFileToStdout` | prints the full report to stdout instead of a file | | `-XX:+ErrorFileToStderr` | prints the full report to stderr instead of a file | | `-XX:ErrorLogTimeout` | caps the time spent writing the report (120 seconds by default) | The working directory is often a poor place for it: in a container it is part of a writable layer that disappears when the container is replaced, and on a host it may be a directory nobody looks in. Pointing `ErrorFile` at a persistent directory, and keeping `%p` in the name so a second crash does not overwrite the first, is a cheap habit. ## What you do with it You open the file and read its head first: the signal and the faulting address, the JDK version, and the `Problematic frame:` line, which says whether the crash happened in a native library, in compiled Java code or inside the VM. The rest of the file (the crashing thread's stacks, the VM state, the flags, the memory map, the environment) is what you read next to confirm a hypothesis. Keep every file: several crash logs from the same service, compared side by side, say far more than any single one.
- Why does a container restart often leave you without the hs_err file, and what fixes it?By default the file goes to the working directory, which in a container lives in the container's writable layer. When the orchestrator replaces the container, that layer and the file go with it. Setting `-XX:ErrorFile=/crash/hs_err_pid%p.log` on a mounted volume, or using `-XX:+ErrorFileToStdout` so the report reaches the log pipeline, keeps the evidence.
- The JVM vanished and no hs_err file exists anywhere. What does that absence suggest?That HotSpot's error handler probably never ran. The usual reason is a `SIGKILL` from outside, such as the kernel's OOM killer or a forced stop, which cannot be caught. A normal exit or an `-XX:+ExitOnOutOfMemoryError` exit writes none either. Check the exit code and the kernel log before assuming the file was lost.
An hs_err file is a flight recorder recovered after the crash: you cannot interview the aircraft, so everything you learn comes from what the recorder captured in the last moments.
- Says an uncaught Java exception writes an hs_err file.
- Expects a heap OutOfMemoryError to leave an hs_err file by default.
- Looks only in /tmp and misses the working directory default.
- Thinks the JVM can write a crash log after a SIGKILL.
- Sets ErrorFile without %p, so later crashes overwrite earlier ones.
Assumes JDK 25; the lookup order and the ErrorFileToStdout and ErrorFileToStderr options are as in the jdk25u source.