views:

99

answers:

2

How can I monitor a Windows process and start it up if it is not running? I'd like to have something that starts up as a Windows service and can handle multiple processes.

EDIT: Hopefully there's a ready to use library/component I can use and just tweak or configure instead of having to implement it from scratch. I know in the *nix world of two popular packages: god and monit.

+3  A: 

You can create a Windows Service that just watches the current process list.

EnumProcesses provides the means of seeing processes running currently. There are many APIs available to start a new process, including:

  • system()
  • _exec()
  • WinExec()
  • ShellExecute()/ShellExecuteEx()
  • CreateProcess()
  • CreateProcessAsUser()
  • CreateProcessWithLogonW()

If you're using other languages/frameworks, they often provide their own wrappers around the above.

Reed Copsey
Do you know of anything that already does this (instead of having to reinvent the wheel)?
Abdullah Jibaly
No. However, it's pretty simple to do this in .NET languages - you can make a service that does this with probably <50 lines of code. (Most of the above functions have high level wrappers in the System.Diagnostics namespace, like the Process class, which makes this trivial.)
Reed Copsey
A: 

Hi Abdullah.

Re: existing applications, you may want to check out AlwaysUp. It is designed to keep a process running 24/7 (restarting it if it fails) and has a few advanced features that may be time-consuming to reproduce in your own code.

Good luck.

CoreTech