DB / Linux / 14
WARNING

Linux SIGALRM

SIGALRM is a signal sent to a process when a timer set by the alarm() or setitimer() system call expires. It is typically used to interrupt a blocking operation after a specified time interval.

Common Causes

  • A timer set via the alarm(), setitimer(), or timer_create() system calls has expired.
  • The process is using a library or framework (e.g., for timeouts, heartbeats, or scheduling) that internally manages timers and sends SIGALRM.
  • An external monitoring or orchestration tool (like a health check) is terminating a process that has exceeded its allowed execution time.

How to Fix

1 Identify the Source of the Timer

Examine the process source code or attached debugger to find calls to alarm(), setitimer(), or related timer functions. Use strace to trace system calls.

BASH
$ strace -p <PID> 2>&1 | grep -E '(alarm|setitimer|timer_)'

2 Handle or Ignore the Signal

If the signal is expected, modify the program to handle SIGALRM gracefully using a signal handler (signal() or sigaction()) to perform cleanup instead of terminating.

BASH
$ # Example in C #include <signal.h> #include <stdio.h> #include <unistd.h> void alarm_handler(int sig) { printf("Alarm received. Performing cleanup.\n"); // Custom cleanup logic } int main() { signal(SIGALRM, alarm_handler); alarm(5); // Set timer for 5 seconds pause(); // Wait for signal return 0; }

3 Adjust or Disable External Timeouts

If an external tool (e.g., a process supervisor, health check, or orchestration platform like Kubernetes) is sending the signal, review and increase its timeout configurations.

BASH
$ # Example: Increasing a health check timeout in a Kubernetes deployment YAML # spec: # containers: # - name: myapp # livenessProbe: # initialDelaySeconds: 30 # periodSeconds: 10 # timeoutSeconds: 5 # Increase this value if probes are causing SIGALRM