[英]A server program is on an infinite loop. How to check for it?
A server program is on an infinite loop. 服务器程序处于无限循环中。 How to check for it? 如何检查?
My solution: 我的解决方案
use GDB to check the values of condition variables that control the loop. 使用GDB检查控制循环的条件变量的值。
It is ok for small program. 小程序可以。
how to do that for large program ? 如何为大型计划做到这一点?
If the program is not running in GDB, how to detect the endless loop ? 如果程序没有在GDB中运行,如何检测无限循环?
thanks 谢谢
You could use some form of a watchdog timer . 你可以使用某种形式的看门狗定时器 。 Have the program output a character or touch a file periodically, so if it gets stuck in a loop, a separate process can detect that the watchdog has not been updated and kill/reset the process. 让程序输出一个字符或定期触摸文件,因此如果它陷入循环,单独的进程可以检测到监视程序尚未更新并终止/重置进程。
A lot of microcontrollers have this built into the hardware, and they will automatically reset if you don't reset the timer. 许多微控制器都内置于硬件中,如果不重置定时器,它们将自动复位。 It's very handy :) 它非常方便:)
If the program is running on the server you can attach a GDB process to it by giving its pid. 如果程序在服务器上运行,您可以通过提供其pid将GDB进程附加到它。
So for example look for the pid of the process using ps: 例如,使用ps查找进程的pid:
ps ax | ps ax | grep server_process grep server_process
3789 ?? S 0:00.58 /usr/bin/server_process
3790 ?? S 0:00.58 /usr/bin/server_process
18002 ?? S 0:00.58 grep server_process
You probably want the child: 你可能想要孩子:
so use gdb to attach to the running process 所以使用gdb附加到正在运行的进程
gdb /usr/bin/server_process 3790
.... loads symbols ....加载符号
gdb>
Happy tracing :) 快乐追踪:)
Of course replace server_process with your program name and the path appropriately :P 当然,请将server_process替换为您的程序名称和路径:P
Detecting an infinite loop is called the Halting problem which is undecidable. 检测无限循环称为停止问题 ,这是不可判定的。
So in principle there is no sure way to detect it. 因此原则上没有确定的方法来检测它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.