![]() |
| | #1 |
| Registered User Join Date: Oct 2008
Posts: 5
| How to write/use watchdog in C program |
| tuhin_iub is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Linux has a watchdog already. However, that checks that the OS is not hanging, not that your app is not hanging. I think the easiest way to check if your app is hanging or not is to use some sort of mechanism to tell another process "I'm still alive" and if that's not happening, let the monitor app to restart the system (or the process?) -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Registered User Join Date: Oct 2008
Posts: 5
| >I think the easiest way to check if your app is hanging or not is to use some sort of mechanism to >tell another process "I'm still alive" and if that's not happening, let the monitor app to restart the >system (or the process?) Thanks for reply, can you provide me an example how to write such a machanism |
| tuhin_iub is offline | |
| | #4 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
What do you think you should be doing? Or are you another of those people that have promised that you can do something you actually can't and you are now in trouble to try to solve it? -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
| matsp is offline | |
| | #5 | |
| Registered User Join Date: Oct 2008
Posts: 5
| Quote:
| |
| tuhin_iub is offline | |
| | #6 |
| The MethLab Join Date: Oct 2008
Posts: 110
| Actually it is quite apparent that you don't know what you are doing and how to do this. So what you should do is figure out this relatively simple program, or learn how to use google effectively.
__________________ C Coder, etc etc. |
| MeTh0Dz is offline | |
| | #7 |
| Registered User Join Date: Oct 2008
Posts: 5
| Sorry for my bad english. English is not my first language. Anyway actually I was goggling couple of days about this situation. problem is I did not understand which area I should focus properly. I have always found watchdog in google search. But I don't know that is actually possible to use. It seems like you are much more knowledgeable then me. A simple example or you can tell me wich are I need to look at in C programming language. Thanks in advanced |
| tuhin_iub is offline | |
| | #8 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Ok, here's the rough steps: 1. Set up a pipe You can use a named pipe for an independent monitor process or anonymous if you use fork+exec to create the two different processes. 2. Then the monitor process waits on the pipe using select, with a timeout - how large that timeout should be depends on how long you are willing to wait for your application, which in turn depends on the type of system you are designing. Don't make it TOO short, or you'll run into trouble. http://linux.die.net/man/2/select 3. If the select call times out, then you know that the process didn't send a message, so you restart the system [code]system("shutdown -r now");/code] assuming you have the rights to do that [and if you don't, you are stuffed]. The target application should write to the pipe more often than the timeout. Depending on your applications design and behaviour, you could have a watch-dog tickler in the main loop, or scattered a bit here and there. If you start the monitored process from the monitor process, you could also set up a SIGCHILD handler and detect if the child process falls over - then you have a choice of restarting the whole system or just restarting the process itself. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #9 | |
| Registered User Join Date: Oct 2008
Posts: 5
| Quote:
| |
| tuhin_iub is offline | |
| | #10 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,929
| Nobody cares. Most of us are used to dealing with people that speak english as a second (or third etc.) language. Your failure is not of a grammatical nature. If you cant be bothered to at least attempt to solve the problem, do not expect everyone else to fall all over themselves helping you.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
![]() |
| Tags |
| c-language, linux, watchdog |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Issue with program that's calling a function and has a loop | tigerfansince84 | C++ Programming | 9 | 11-12-2008 01:38 PM |
| Need help with a program, theres something in it for you | engstudent363 | C Programming | 1 | 02-29-2008 01:41 PM |
| This is a simple program.. Help me please I think it has an error.. | lesrhac03 | C Programming | 4 | 02-21-2008 10:39 AM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |