none
CPU usage RRS feed

  • Question

  •  

    I have to write a small service which will monitor the CPU usage and if a particular process consumes more than a predefined amount of CPU for a certain duration of time (that is, if this process is responsible for "hanging" the server), this service will kill that process and then restart it (of course, only if this process is one of the "custom" programs, not a system process).

    My question is:

    is there a programmatical way of determining the CPU usage at the moment? [I am going to use a Timer which will do that once in a few minutes.]

    Could someone give me a link to an article describing how to do this, please?

    Thank you very much.

    Friday, April 28, 2006 6:16 PM

Answers

  • Take a look at this article over on The Code Project on how to determine the CPU time of all processes on the system. It should be trivial for you to make it only work on those processes you specify.

    As for killing the process... this example used the Process class, you can simply call the Kill() method on it to nuke it.

    When it comes to restarting... that is a little more tricky. Ideally you would have specified for your application the location of the process... if you’ve got that then you can create a new instance of the Process class and use the Start() method.

    Friday, April 28, 2006 6:50 PM
    Moderator
  • Have a look at the following blog post on the BCL Blog: http://blogs.msdn.com/bclteam/archive/2006/06/06/619284.aspx.
    Thursday, June 8, 2006 1:36 AM
    Moderator

All replies

  • Take a look at this article over on The Code Project on how to determine the CPU time of all processes on the system. It should be trivial for you to make it only work on those processes you specify.

    As for killing the process... this example used the Process class, you can simply call the Kill() method on it to nuke it.

    When it comes to restarting... that is a little more tricky. Ideally you would have specified for your application the location of the process... if you’ve got that then you can create a new instance of the Process class and use the Start() method.

    Friday, April 28, 2006 6:50 PM
    Moderator
  • Have a look at the following blog post on the BCL Blog: http://blogs.msdn.com/bclteam/archive/2006/06/06/619284.aspx.
    Thursday, June 8, 2006 1:36 AM
    Moderator