My computer often gets CPU spikes, and I want to use C++ to find out what is causing the problem the close it. I have looked around a bit and seen that system() might be good for closing something but I'm not sure how to, + i need to find out how to get info about CPU usage.
Ever hear about the task manager? It tells you cpu usage and you can close programs. System is also kind of bad to use ( also only for windows but so is task manager also I suppose. ) If you really want to make a program to mimic the task manager someone else will have to help you out with that :p
There's also Process Explorer, which gives a lot of information, including nice graphs of CPU, I/O and memory usage of a particular process. I think of it as a step up from task manager.
There's also the Windows Performance Monitor MMC snap-in, if your talking about apps. Either launch it via the shell, or you can run it from a command console as perfmon.exe actually perfmon.msc (edit: more correct, for the modern version.)
The Performance Monitor snap-in (edit: to use its new name) is kind of a more souped up version of Task Manager which can save configurations, log output, etc.
Well, then you need to use the Performance Counters or the WMI API to monitor the processes, and then close them if they get out of hand.
To close an app gracefully, you should ask it politely to close, by posting it a WM_CLOSE message. Only if it ignores you should you use TerminateProcess.
You also have to have the right grant yourself the privilege to terminate the process before you can actually do so, using AdjustTokenPrivileges, etc. Which might be a bit of a problem.