Vig*_*shK 3 c++ linux embedded embedded-linux
我想在linux中使用定时器中断来做软件wathdog定时器.我怎样才能在linux中生成定时器中断?
如果要使用定时器中断,请使用信号,尤其是SIGALRM.您可以使用函数alarm()来请求超时.如果你想要usec粒度,你可以使用ualarm().一旦达到超时,它将调用您之前定义的回调函数.
这是一个示例代码:
#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)
;
}
Run Code Online (Sandbox Code Playgroud)
您实现监视程序的其他选项很少:
| 归档时间: |
|
| 查看次数: |
5855 次 |
| 最近记录: |