Monitoring Process Termination

Posted on 2012-09-20
Last Modified: 2012-09-25
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.

Question by:ChrisNillissen
    LVL 9

    Expert Comment

    by:Ashok Dewan
    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.

    Download link from microsoft  ;-

    Author Comment

    Thanks for your reply, but I forgot to mention that I am trying to accomplish this programatically with Delphi.
    LVL 25

    Accepted Solution

    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:

    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") ...

    you can benefit from this too...
    LVL 21

    Expert Comment

    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).
    LVL 36

    Expert Comment

    by:Geert Gruwez
    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

    Author Comment

    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.
    LVL 21

    Expert Comment

    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.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now