Click here to Skip to main content
15,860,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello CP,

I'm working on a system to auto-shutdown processes using 100% cpu for longer than an x amount of time.
Some programs and games such as flash tend to take 100% processor time and some DirectX games freeze the computer yet the music keeps playing perfectly.

The fact that the music is playing makes me think that there are still a few bits running wild and I could perhaps use this to kill the 100% process.

So what I'm looking for is an app, or more preferably a C# program (inc. source), that can freeze the computer for testing purposes.

Thanks in advance.

With kind regards,

Nbgangsta
Posted
Comments
Dave Kreskowiak 6-May-11 11:13am    
Just because sound is still playing doesn't mean anything. The sound card (chip) offloads playing the music from the CPU, freeing the CPU to do other things.

I agree with John. Your goal is impractical and doesn't solve the problem of processes hanging. If you've got processes that frequently hang, then you've got a much bigger problem with your system than those applications.

I think your goal is impractical. It's difficult/impossible to determine *why* a task is consuming 100% CPU, and even more diffcult to determine how long it's been at 100%. Just indiscriminately shutting down 100% tasks is - well - pointless.
 
Share this answer
 
Comments
Groulien 6-May-11 7:36am    
You're right that it's difficult, but that's also why I find it an interesting topic.
The act of filtering which processes should and shouldn't take 100% is something I had already taken into account (and thought you would assume that I would filter it).
Things such as Flash and IExplorer should not take 100% cpu for example and many games don't run at 100% for longer than 60 seconds straight.
Thanks for the feedback.
Sergey Alexandrovich Kryukov 6-May-11 11:03am    
I kinda agree with OP that the topic is (somewhat) interesting, but nevertheless the task itself is pointless, in my opinion. My 5.
--SA
Simulating a 100% CPU usage isn't difficult. You just need to create as many threads as you have CPU (or cores) and make them run an infinite loop while(true);.
To make your computer responsive (even though your process will use 100% CPU), you can lower your process priority (see Process.PriorityClass).

After that, if you want to run a background process that periodicaly checks other processes, I suggest that you make this process a high priority (High is enough, don't use RealTime), and you can retreive processes time information with Process.TotalProcessorTime.
For example if you check every second, and this value is increasing to "almost" 1 second, then you can deduct that it uses close to 100% CPU.

Remember that a 100% CPU usage is not necessarly responsible for blocking your computer. If the process has a very low priority, then it shouldn't be a problem.
 
Share this answer
 
v2
Comments
Groulien 6-May-11 8:36am    
Thank you for you solution.
It's true that 100% CPU doesn't necessarly block it, it's just that it happens in a lot of cases (here).
The 100% CPU simulation is a reasonably well known trick, nearly every beginner gets it rubbed into his face with the while(true) statement.
The tip for the PriorityClass was something that had completely slipped my mind, big thanks for that.
Olivier Levrey 6-May-11 8:41am    
You are welcome.
If you consider that your problem was solved, you can accept my solution. Otherwise if you have other questions you can use the "improve question" widget or drop another comment.
Sergey Alexandrovich Kryukov 6-May-11 11:02am    
Agree. My 5. It's especially important to understand that 100% CPU does not means blocking (come to think about).
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900