Catch the exact moment your app crashes before the logs rotate

Process & Resource Monitoring (Top/Htop/Ps/Systemd)

Catch the exact moment your app crashes before the logs rotate

🧩 The Challenge

Dealing with a service that dies silently at 3 AM is the worst kind of mystery. You check the logs the next morning and find nothing but a cryptic restart message.

💡 The Fix

Use systemd’s ability to run a command the second a process exits. It’s perfect for capturing a stack trace or a process dump while the memory is still warm.

systemctl edit your-service.service
[Service]
ExecStopPost=/usr/bin/gcore -o /tmp/coredump-%n-%u %P

⚙️ Why It Works

Adding an ExecStopPost directive ensures that the system triggers your diagnostic script regardless of whether the service crashed or was stopped normally. Since it fires immediately upon termination, you don’t lose the volatile state of the process memory.

🚀 Pro-Tip: Pipe that gcore output straight to a compressed file if your app has a massive memory footprint, otherwise you’ll fill up /tmp in a heartbeat.

Linux Tips & Tricks | © ngelinux.com | 12/2/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted