WatchDog Timer In Linux
If you want to use timer interrupts, use signals, and especially SIGALRM
.
You can use the function alarm() to ask for a timeout. if you want usec granularity you can use ualarm().
Once the timeout has reached it will call a Callback function you defined before.
Here's an example code:
#include <signal.h>
void watchdog(int sig)
{
printf("Pet the dog\r\n");
/* reset the timer so we get called again in 5 seconds */
alarm(5);
}
/* start the timer - we want to wake up in 5 seconds */
int main()
{
/* set up our signal handler to catch SIGALRM */
signal(SIGALRM, watchdog);
alarm(5);
while (true)
;
}
You have few other options for implementing a watchdog:
- Write / Use a kernel driver, which actually works as a watchdog, applying a hard reset to the device if the dog is not pet (or kicked)
- Use an watchdog, an interesting implementation of a software watchdog daemon.
How to debug a watchdog timeout
Add an uninitialized global variable that is set to different values throughout the code. Specifically, set it before and after major function calls.
Put a breakpoint at the beginning of main.
When the processor resets the global variable will still have the last value it was set to. Keep adding these "bread crumbs" to narrow down to the problem function.
Related Topics
What Does the "Mov Rax, Qword Ptr Fs:0X28" Assembly Instruction Do
How to Access the Base Filename of a File You Are Sourcing in Bash
Extract Text Between Two Strings Repeatedly Using Sed or Awk
The New Line Characted in the String Constant Isn't Being Recognized by Nasm
Cron Error with Using Backquotes
How to Monitor Newly Created File in a Directory with Bash
Does Linux Support Memory Isolation for Processes
Printing Grep Results to File and Terminal
Automatic Syntax/Headers in Vim for C++ Files
How to Check If a File Contains Only Zeros in a Linux Shell
Converting a Pcap Trace to Netflow Format
What Is Echo $? in Linux Terminal
Save Modifications in Place with Non Gnu Awk
How Many Instructions Does Linux Kernel Need in Order to Handle an Interrupt on an Arm Cortex A9