Monitor an application - kill and regenerate if hang

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!
[472 byte] By [Yijie] at [2007-11-20 10:51:58]
# 1 Re: Monitor an application - kill and regenerate if hang
Google Windows Performance Monitor (maybe with C++ in there), and scan through for code examples.

However, some programs hang in such a way that no CPU time is occupied, which looks like any otherwise functioning program that's just waiting.
JVene at 2007-11-9 13:59:35 >
# 2 Re: Monitor an application - kill and regenerate if hang
Double posted. See my response in the other forum.
Arjay at 2007-11-9 14:00:35 >