Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Monitor an application which required kill and regenerate if hang

How to Monitor an application which required kill and regenerate if hang

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    littlecheer
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • L littlecheer

      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

      N Offline
      N Offline
      Nathan Holt at EMOM
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • N Nathan Holt at EMOM

        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

        L Offline
        L Offline
        littlecheer
        wrote on last edited by
        #3

        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!

        D 1 Reply Last reply
        0
        • L littlecheer

          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!

          D Offline
          D Offline
          devvvy
          wrote on last edited by
          #4

          one idea: use Sysinternals' pslist - (1) have another periodically run pslist (2) pipe the output the a flat file, (3) then your *other* application to parse the file for CPU usage (4) If ProcessA.CPU>30 Then killtask

          T 1 Reply Last reply
          0
          • D devvvy

            one idea: use Sysinternals' pslist - (1) have another periodically run pslist (2) pipe the output the a flat file, (3) then your *other* application to parse the file for CPU usage (4) If ProcessA.CPU>30 Then killtask

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            devvvy wrote:

            1. 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

            D 1 Reply Last reply
            0
            • T ThatsAlok

              devvvy wrote:

              1. 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

              D Offline
              D Offline
              devvvy
              wrote on last edited by
              #6

              well change 30 to any number you like

              L 1 Reply Last reply
              0
              • D devvvy

                well change 30 to any number you like

                L Offline
                L Offline
                littlecheer
                wrote on last edited by
                #7

                My current monitoring application is written in C++ console. Is it possible to use C++ coding to solve this problem? Thanks a million.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups