We help IT Professionals succeed at work.

How to detect wheather an application has stopeed responding

msrijna
msrijna asked
on
How to write an application using C++ to detect if an application written in c++  has stopped responding or not.
Comment
Watch Question

Commented:
msrijna,

are you trying to determine if an application has shutdown or if it is able to communicate to another app?

Author

Commented:
I am trying to find if an application has hung or stopped responding.
This application is written in C++ and it continuously runs on server.So i want to write an application to detect if that C+= application as stopoed responding or not.I want to write an application in C++

Commented:
msrijna,

This application that continuously runs.. does it perform some type of communication to database? I can tell you if an instance of a program is up and running, but it will be hard to determine if a program is responding or hung.  You've got to give me a little more detail about the app..  What is the app communicating to?

DrMaltz

Author

Commented:
I have got a CGI application which communicates to mainframe and foxpro database using this application which continuously runs.
So this application  called "Event Monitor"  is an interface between main CGI application( in C++) and different database ( mainframe and foxpro database).
Event Montor is written in VC++ 6.0 and it runs continuosly and it receives request from CGI application and sends it to mainframe and then receives data from mainframe and send s it back to CGI application.
Sometimes this Event Monitor hangs or stops responding to CGI application requests ( because of some bad data ) and everthing stops.
So Iam trying to find out a way to determine as when this Event Monitor stops responding because of application error.So taht when it hangs I can alarm the support people ( by sending email to their pager )about the problem.
Let me knwo if you need any more details.

Commented:
msrijna,

Does the EventMon application send out an error message to a log or to something like NT EventViewer..?

Currently, how do you know it has hung?

Author

Commented:
No it does not log anything to NT Eventviewer.As of now when I run CGI application and if it does not repond that means CGI application is not able to communicate to mainframe through event monitor .So event monitor must b down .
Or by looking at the server where vent monitor is running.When it crashes itt hanges and shows application error
Please help

Commented:
msrijna,

Well, the only thing I can think of is using the SendMessageTimeout function.  I'm assuming you're running your app on Windows.  This is the same function used by taskmanager to determine that an application is not responding.

This function sends a message and waits until it gets a response or a specified number of milliseconds pass. The function will return immediately if the receiving program is hung.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/messques_9l4k.asp

Good Luck,

DrMaltz

Author

Commented:
No it does not log anything to NT Eventviewer.As of now when I run CGI application and if it does not repond that means CGI application is not able to communicate to mainframe through event monitor .So event monitor must b down .
Or by looking at the server where vent monitor is running.When it crashes itt hanges and shows application error
Please help

Author

Commented:


I hav trid that funstion of SenMessageTimeout but iam trying to write a application which could do this .I mean which could detect if any application is responding or not.
Could you suggest if there is any site where I could get code for that application.

Commented:
msrijna: As far as I know, Windows detects an application isn't responding when it stops responding to messages, so SendMessageTimeout() is as good a way as any to find out if your app is still running.
Commented:
There's plenty of sample code out there.. Here's how your code would look.
//
DWORD result;
if(!SendMessageTimeout(wnd->m_hWnd,      // target window
                       UWM_QUERY_SOMETHING, // message
                       0,                   // WPARAM
                       0,                   // LPARAM
                       SMTO_ABORTIFHUNG |
                       SMTO_NORMAL,
                       TIMEOUT_INTERVAL,
                       &result))
{ /* error or timed out */
    // take some appropriate action on timeout or failure
    // if we care, we can distinguish timeout from other
     // errors
    if(::GetLastError() == 0)
    { /* time out */
        // take timeout action
    } /* time out */
    else
    { /* other error */
        // take error action
    } /* other error */
} /* error or timed out */
else
{ /* successful */
    // decode the result
    switch(result)
    { /* result */
    case ...:
        break;
    case ...:
        break;
    } /* result */
} /* successful */

Good Luck,
DrMaltz

Commented:
Did U see the taskmanager showing App notresponding .

ON windows implementation Taskman will send WM_NULL message to the message queue of the application. If it returns otherthan messagetimeout its considered as functioning .Otherwise if that SendMessageTimeout function returns TIMEOUT

DWORD lngResult;
SendMessageTimeout( HWND /* handle to window */, WM_NULL, 0,0, SMTO_ABORTIFHUNG, 1000, &lngResult)

if the return value is zero the program is notresponding.


same thing as DrMaltz  written.


   

Commented:
Dear msrijna

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "DrMaltz"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner

Author

Commented:
I accept it
Thanks

Commented:
msrijna

Please d me the favour and accept the answer yourself. There is a button next to the comment that says "accept comment as answer", very easy!

Thanks for your feedback.

======
Werner

Explore More ContentExplore courses, solutions, and other research materials related to this topic.