Module 6 · Lesson 68 of 108

Field crash capture and signal handling

Collect evidence for remote crash diagnosis and choose a fatal-signal policy that preserves useful diagnostics.

  • Beginner to advanced
  • 8 min read
  • 20 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM; Bash; access to a disposable environment for the crash test

Your place in the module
By the end you can 4 objectives
  • Assemble a crash report with a core or capture status, relevant logs, and a timestamped state snapshot.
  • Identify the executable and shared libraries needed to interpret a field core.
  • Explain how SIGSEGV and SIGABRT should terminate a service and constrain any custom handler.
  • Choose where to run backtrace() or libunwind for a given diagnostic task.
Video coming soonField crash capture and signal handling
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Detecting hangs and crash dumps
  • A systemd watchdog expires when the service stops sending accepted watchdog notifications within its configured interval.
  • The kernel uses core_pattern to decide where to send a core dump.
  • GDB needs the original executable and matching symbols to resolve application frames accurately.
01

What to collect from a field crash

3 min read

Crashes in the lab are easy to catch; this lesson covers capturing them in the field and handling fatal signals safely.

Linux documents a case that matters on an embedded device: when /proc/sys/kernel/core_pattern starts with |, the kernel sends the dump to a user-space program. A service can die with a core-producing signal and leave no file in its working directory. The collector may keep the dump elsewhere, retain only metadata, or fail to store it. Before relying on a deployment image, test where a dump goes and whether support can retrieve it. core(5)

A useful crash report contains three kinds of evidence:

  • Core and crash metadata. Keep the core when the product policy allows it. Record the executable identity, architecture, image version, signal, process ID, boot ID, and crash time. If a core is unavailable, record what the collector reports. Distinguish a known policy decision or storage failure from an unknown outcome.
  • Logs around the failure. Keep a bounded window of service and relevant system logs. Include the last completed operation, errors leading up to the crash, and any subsequent supervisor messages. A process can die before its buffered output is flushed. Record important transitions as they happen so recent history is available outside the process.
  • State snapshot. Save a small, timestamped record of the values needed to interpret the logs. For a gateway, that might include the service state, the active configuration revision, the last successful transaction time, and the number of pending requests. Record when the snapshot was taken. A snapshot from before the crash records the last observation. A snapshot taken after restart describes the new instance.
What a crash report retainsCoreLogsSnapshotRecordsCapturedprocessmemoryEvents aroundfailureObservedservice stateNeedsMatchingreleaseartifactsBoot andinstanceObservationtimeIf unavailableCapturestatusAvailabletime windowMissingfields
A remote crash report associates a core or capture status with logs and a dated snapshot

Give the report an incident ID and associate it with a boot and a service instance. You can read the current boot ID from /proc/sys/kernel/random/boot_id. Within that boot, record the process start time or a supervisor-provided instance identifier alongside the PID. A PID can be reused. If the device clock is corrected after boot, wall-clock timestamps can jump. Preserve monotonic timestamps where available to order events within a boot, and label their clock source.

Collect service state during normal operation, or have another process observe it. For example, the gateway can periodically publish a short snapshot that the collector can read after the service dies. If the collector queries the supervisor after a restart, it should use the recorded process identity to keep observations from the old and new instances distinct. Record which fields were unavailable. A missing queue depth tells the engineer something different from a queue depth of zero.

Keep the exact release executable and shared libraries, with matching debug information, in your release archive. A version label is useful for support, but a build ID, when available, lets the engineer match an individual ELF artifact to its debug information. A field binary can be stripped while symbols stay in the archive. Match the target architecture and build when opening the dump. Even two builds from the same source can have different address layouts.

02

How to handle SIGSEGV and SIGABRT

3 min read

SIGSEGV commonly comes from an invalid memory access. SIGABRT commonly comes from abort(), for example when a program detects an invariant violation and decides to terminate. Linux gives both signals a default action that terminates the process and attempts a core dump. Keep these default dispositions for a service that relies on the kernel and an external collector. This lets Linux record the original fatal signal and, when capture succeeds, retains the state needed to inspect the failing thread.

A custom handler runs inside the failing process. The signal can arrive while the thread holds a lock, updates a data structure, or executes library code. For example, a handler that calls printf() can interrupt code that is already operating on a stdio stream. Calling into stdio again can encounter that stream in the middle of an update. A crash can also leave the heap damaged, so allocating memory to build an error message can cause a second failure.

An has a specific guarantee. Use the list in signal-safety(7) when reviewing handler code. Keep printf(), malloc(), mutex locking, and normal logging calls out of a fatal handler. Leave file formatting, compression, and network upload to the collector. Even a call that is async-signal-safe can block. For instance, writing to a full blocking pipe can stop the fatal path from finishing.

Default fatal-signal processingFatalsignalSIGSEGV orSIGABRTDefaultactionApply dumppolicyRouteeligibledumpCompleteprocessexitFatalsignalSIGSEGV orSIGABRTDefaultactionApply dumppolicyRouteeligibledumpCompleteprocessexit
The default fatal-signal action gives Linux the original crash context for core capture

If a product requires a final notification, install the handler with sigaction() during startup and check the result there. Prepare a dedicated nonblocking pipe before installing the handler. Its reader should be a separate process. On Linux, a single write() of a fixed marker no larger than PIPE_BUF to a nonblocking pipe either writes the entire marker or, if there is insufficient space, fails with EAGAIN. Treat the marker as best effort and continue termination on failure. Account for a missing reader as well: writing to a pipe with no reader can generate SIGPIPE. The marker only reports that the handler ran. It does not prove a core was stored.

Plan how a custom handler terminates. Returning from a handler for a synchronous SIGSEGV from a bad memory access is unsafe. For a best-effort notification handler that must preserve signal-based termination, one Linux approach is to restore the original signal's default disposition with sigaction(), unblock that signal in the calling thread with sigprocmask(), then send it to the same thread with raise(). Check for failure and use _exit() as a fallback if the sequence fails or control reaches the end. The re-raised signal can cause a core under the active dump policy, but its signal information and capture context can reflect the re-raise rather than the original fault. _exit() gives an ordinary exit status and does not trigger a signal-generated core. Use the default disposition directly when the original crash context matters.

sigaction() also supports SA_SIGINFO for handlers that need the signal information. For a kernel-reported segmentation fault, the supplied siginfo_t can include the fault address. A signal sent explicitly for a test has a different origin, so a test that sends SIGSEGV does not establish that a real fault address is available. If you must handle stack exhaustion in a custom handler, SA_ONSTACK can run it on an alternate signal stack registered with sigaltstack(). Register that stack during normal execution on each thread that needs it. An alternate stack supplies space for the handler and leaves the signal-safety rules in force.

03

Where to unwind and how to verify collection

3 min read

A stack trace lists the function calls an unwinder can reconstruct. glibc's backtrace() collects return addresses for the calling thread. It can be useful at a deliberate diagnostic point during normal execution. It has no async-signal-safety guarantee. On Linux, a first call can cause the unwinding support library to be loaded, which can allocate memory. Calling backtrace() once at startup may avoid that particular loading step later, but it does not establish that subsequent calls are safe in a handler.

Libunwind also walks stacks. Its signal-safety properties depend on the specific operation and context. Check the documented guarantee for every operation before using it in a signal handler, including initialization and any name lookup. A stack walk can be incomplete when stack data is damaged or unwind information is missing. Compiler optimizations, including inlining and tail calls, can also change which calls appear as frames. For field crash diagnosis, prefer unwinding from the core with a debugger and matching release artifacts. The debugger can inspect the failing thread and other captured threads without calling functions inside the crashed process.

From field capture to analysisRetainincidentevidenceRetrievereportMatchreleaseartifactsInspectcapturedthreadsRetainincidentevidenceRetrievereportMatchreleaseartifactsInspectcapturedthreads
The collector retains evidence while support matches the dump to the shipped build and inspects it

Check capture on the deployed service configuration. From a shell, these commands show the kernel route and the current shell's soft core size limit:

bash
cat /proc/sys/kernel/core_pattern
ulimit -S -c

The shell limit is the one inherited by processes it starts unless they change it. Check the actual service's limit in /proc/<pid>/limits while it is running. With a pipe pattern, Linux ignores RLIMIT_CORE for deciding whether to send the dump to the pipe handler. The receiving program can still apply its own limits. Test the effective configuration on the target image, including where the collector writes when the root filesystem is read-only.

Run a controlled test in a disposable environment with a synthetic workload. This command sends SIGABRT to a child Bash process and leaves the calling shell available to inspect the result:

bash
bash -c 'kill -s ABRT "$$"'

Record the route and find the dump or the reason it was unavailable. An exit reported by the shell establishes that the child died. Confirm storage separately by retrieving the artifact through the configured collector. A test of a shell process checks that environment's route. Repeat the validation with a disposable instance launched under the service's own configuration before relying on it in production.

A field collector needs writable storage with a size limit, retention rules, and a way to retry uploads after a disconnection. Restrict access and use authenticated, encrypted transfer. A core can contain credentials or customer data from process memory. Select log and snapshot fields explicitly, and retain a small crash record when policy omits the core. Verify the report can be retrieved after a restart and that support can identify its matching build.

The next lesson, Logging, metrics, and observability, explains how to keep the operational evidence that gives a crash report its context.

Key takeaways

  • A fatal signal can terminate a process even when the device retains no core.
  • A useful report ties the core, logs, and snapshot to the same boot and service instance.
  • The default disposition preserves the original fatal signal for kernel crash capture.
  • glibc backtrace() has no async-signal-safety guarantee, and libunwind safety depends on the specific operation.
Reflect
  1. Explain to a colleague, in two sentences: assemble a crash report with a core or capture status, relevant logs, and a timestamped state snapshot.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close