|
The corrupted variable was allocated on heap..
thanks though...
|
|
|
|
|
Hi all,
Do need a favour here. I would like to monitor an application and kill it if it is hang and regenerate it. However, not able to find relevant code.
I'm able to get the kernel and user time by "getprocesstime". But not able to monitor the CPU usage (not able to get idle time) to kill the hang program.Understand that some programmer use "GetSystemTimes" function. But it does not work in my PC.
Any suggestion or free code to share? Thanks a lot!
-- modified at 23:29 Wednesday 19th September, 2007
|
|
|
|
|
littlecheer wrote: Do need a favour here. I would like to monitor an application and kill it if it is hang and regenerate it. However, not able to find relevant code.
I'm able to get the kernel and user time by "getprocesstime". But not able to monitor the CPU usage (not able to get idle time) to kill the hang program.Understand that some programmer use "GetSystemTimes" function. But it does not work in my PC.
Any suggestion or free code to share? Thanks a lot!
There are lots of ways for a program to hang. For instance, I've had just the user interface fail and the program keep running in the background. If you control the code for this program, you could have it periodically signal your monitor program that it's still working. If not, your problem is a lot more dificult.
Nathan
|
|
|
|
|
I see. Based on my understanding, the hang program will reflect very high CPU usage (program in a loop) or usertime and kerneltime unchange (deadlock). Is it possible to trace the particular application's CPU usage? Thanks a lot!
|
|
|
|
|
one idea: use Sysinternals' pslist -
(1) have another periodically run pslist<br />
(2) pipe the output the a flat file, <br />
(3) then your *other* application to parse the file for CPU usage<br />
(4) If ProcessA.CPU>30 Then killtask<br />
<br />
|
|
|
|
|
devvvy wrote: 4) If ProcessA.CPU>30 Then killtask
many of myserver application are so cpu savvy , it runs on 30-40% i.e. when acquring data from hardware at 20hz( i.e. 20 record per second). that will help ful atleast in my case!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
well change 30 to any number you like
|
|
|
|
|
My current monitoring application is written in C++ console. Is it possible to use C++ coding to solve this problem? Thanks a million.
|
|
|
|
|
|
|
|
if you file get deleted.when you download the file!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hello 2 everyone interested!
I am developing an application using a GPS receiver for PPC. I am using threads in my code, one of them deals with the GPS's functionality. I have 2 buttons on the dialog (using MFC, by the way) - GPS>on and GPS>off. If I start the gps, at some point stop it and in a matter of up to 5 seconds (or so) I start it again, I get an error and the application crashes.
If I wait more than those 5 seconds, everything works fine. I have started logging my application's steps after hitting GPS>off and discovered that it reaches to ending the thread after .. right... those aprox.5 seconds.
So, for now, I only start the thread if a flag is set (I set it just before ending the thread).
Because I don`t want it to just ignore the push of the button, I did
do {}while(flagThreadStopped!=true)
so now, everything stops if the user starts the gps in those critical 5 seconds. It resumes, after the flag gets set, but I think if there could be another solution.
It's not a critical problem now, as I'm developing the concept, but... later on, it could be. Ideas ?
Thanks
|
|
|
|
|
shpid3r wrote: Because I don`t want it to just ignore the push of the button, I did
do {}while(flagThreadStopped!=true)
so now, everything stops if the user starts the gps in those critical 5 seconds. It resumes, after the flag gets set, but I think if there could be another solution.
It's not a critical problem now, as I'm developing the concept, but... later on, it could be. Ideas ?
I would add a status message to indicate whether the GPS is off, on, or turning off. I would also set it up to disable the "on" button when turning the GPS on isn't workable. I would set up a timer to update the UI a few times a second, as well as updating it whenever a button is pressed. Also, there's no need to set a flag if the background thread is really exiting. You can call a wait function (WaitSingleObject etc.) on the thread handle, which is considered signaled when the thread exits. When updating your UI, you can do the wait with a time out of 0, and check the return value for status info.
Nathan
|
|
|
|
|
Well, let me discuss your ideas one by one:
-you cannot determine when the gps is turning off. That Is, the function that closes the GPS Device doesn`t return a Handle (to use WaitForSingleObject) but a DWORD. Therefore, once you have commanded it to close, it's going to close in a certain time. Your flags all set accordingly to GPS Off, though 5 seconds it's on Turning_OFF mode, so to say.
- I do refresh my screen once every 100 ms (I've set a timer which I use for audio buffering, as well). I didn`t quite understand what you`re suggesting me to do here... Please expand
Thanks for suggestions!
|
|
|
|
|
shpid3r wrote: -you cannot determine when the gps is turning off. That Is, the function that closes the GPS Device doesn`t return a Handle (to use WaitForSingleObject) but a DWORD. Therefore, once you have commanded it to close, it's going to close in a certain time. Your flags all set accordingly to GPS Off, though 5 seconds it's on Turning_OFF mode, so to say.
You mentioned a background thread, which is a good idea for this sort of problem. You gave me the impression that the background thread terminates when the GPS is closed, which would allow you to just wait for the thread to terminate. Your approach of setting a flag should work regardless.
shpid3r wrote: - I do refresh my screen once every 100 ms (I've set a timer which I use for audio buffering, as well). I didn`t quite understand what you`re suggesting me to do here... Please expand
The idea is that instead of pressing "Off" and having the program hang for 5 seconds, the "Off" button could begin the operation in the background, and while it is happenning, there will be a message on the dialog indicating that the GPS is turning off, and both the "On" and the "Off" buttons will be disabled for the time. Then, when your refresh detects that the GPS is fully off, it can change the message and enable the "On" button. Throughout the whole process, the user could continue to use any features that don't depend on the GPS.
Nathan
|
|
|
|
|
hm... veeery interesting. Great!
Yes, I do use a background thread and I do have a flag that detects when user has pressed off and another one for when the gps has got into OFF state, for good. So some sort of control I do have.
I should mention that I start / end the thread when pushing on / off.
I find it interesing to create a new thread to deal with the operations for the OFF button. Sounds ... it should have been the first thing to think about, but what`s awkward for me is that when pressing the On button, a thread starts. So when Off-ing, I should start a new thread to watch the first thread finishing off-ing
I somehow understand what you mean... sounds like it will work, I`ll try it and come back with an answer (i`ll leave home for the weekend)
Thanks for your suggestions!
---
One chance in a million is still a chance!
Shpid3r
|
|
|
|
|
shpid3r wrote: I find it interesing to create a new thread to deal with the operations for the OFF button. Sounds ... it should have been the first thing to think about, but what`s awkward for me is that when pressing the On button, a thread starts. So when Off-ing, I should start a new thread to watch the first thread finishing off-ing
If you're already running a background thread, your background operation could probably instruct the thread to turn the GPS off, and you could keep updating the status without starting a third thread. On the other hand, if the background thread is entirely controled by third party code, a third thread which you control makes sense.
Nathan
|
|
|
|
|
I am writing a little diagnostic code to run on a Citrix server, accessed through a thin client. I have put loggin messages in that print to an ofstream. There are some points that I would like the memory address of, so in my file, I say:
out << "Memory address: " << &somePointer << endl;
This produces:
Memory address: 0x0013F16C
We also have a message logging function that takes CString types and writes them to a log file. I'd like to have the same type of info in that log file. However, I can't figure out how to get the hex memory address appended to the CString.
Any ideas?
|
|
|
|
|
USAFHokie80 wrote: I'd like to have the same type of info in that log file.
So what's the problem?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
As it says in the bottom: I can't figure out how to get the hex address appended to the string.
------
But I just figured it out so nevermind.
|
|
|
|
|
USAFHokie80 wrote: ...how to get the hex address appended to the string.
out << somePointer << &somePointer << endl;
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
USAFHokie80 wrote: We also have a message logging function that takes CString types and writes them to a log file. I'd like to have the same type of info in that log file. However, I can't figure out how to get the hex memory address appended to the CString.
You can get the char * pointer with LPCTSTR(string) . From there, you can output the value like any other pointer.
Nathan
|
|
|
|
|
How about
void *pSomePointer;
...
CString str;
str.Format(_T("The value of the pointer is 0x%p"), pSomePointer);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
CString::Format!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|