Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1194
  • Last Modified:

Monitoring Process Termination

There are a set of processes that I monitor from my application (using their Process Ids) and check to see when they are terminated. Is there a way to monitor if the Temination of the process was expected or unexpected?

I am trying to capture whether the process that terminated has crashed or not.

Thanks
0
Chris Nillissen
Asked:
Chris Nillissen
1 Solution
 
Ashok DewanCommented:
you can monitor a particular process or more than one process with the help of process monitor by microsoft. use below guide to for tutorial.

http://www.k-state.edu/its/security/training/2009-4-9/presentations/handouts/Process_Monitor_Tutorial_Handout.pdf

Download link from microsoft  ;- http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
0
 
Chris NillissenAuthor Commented:
Thanks for your reply, but I forgot to mention that I am trying to accomplish this programatically with Delphi.
0
 
Sinisa VukCommented:
If you try to run your own application and see if it is terminated normally or not use CreateProcess, wait and after termination check error with GetExitCodeProcess:
http://www.swissdelphicenter.ch/torry/showcode.php?id=93

If you want to check specific process after it was run then you must use OpenProcess
and similar to upper wait and check with GetExitCodeProcess.
Look this sample (find "CloseMainApp") ... http://blog.marcocantu.com/blog/auto_updating_programs.html

you can benefit from this too...
http://www.aldyn.ru/products/perfutils/index.html
http://thundaxsoftware.blogspot.com/2010/01/monitoring-processes-with-delphi.html
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
developmentguruCommented:
Are these processes you wrote?  If they are then you can have the process send you a message every so often as a keep alive signal.  If you stop receiving the signal you can shut it down and restart it.

  When Windows states that a process is not responding, it really means that it is not responding to messages.  This means that you could easily check that yourself (send a message and wait for a period of time for the response).  If you start the process yourself then you can monitor when it completes I believe sinisav's first example).
0
 
Geert GruwezOracle dbaCommented:
if these are your own programs
simplest method is to create a specific file at startup
and delete the file when the app finishes normally (last step in project code)

> if the file exists and your app isn't running, then it was closed unexpectedly
0
 
Chris NillissenAuthor Commented:
I am not looking to check if a process is hung, I am looking at getting the exit code of any number of processes when they terminate. These can be any process not just my own processes.

Thanks Sinisav, the GetExitCodeProcess is just the function call I need to get the processes Exit Code.

I guess the remaining part is what is the best way to get notifications of the process terminations to then trigger this call? I have a list of process id's that I manage and that gets dynamically updated for the processes that I wish to monitor. Unless I am mistaken the WaitFor*Object functions seem a bit restrictive to use in these cases.
0
 
developmentguruCommented:
They could be used in side threads, one thread per process.  The thread would exit when the process finishes, and it has called the GetExitCodeProcess.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now