An application I'm contributing to fires up a component written in C.
The C process does some pretty heavy crunching and if your not careful can really hammer your CPU.
Is there a way to set a limit to external processes spawned by .NET?
I've seen this artivcle on setting a hard memory limit at the OS level, is there a similar thing for CPU?
I had the same problem. I solved it by using SetInformationJobObject Kernel32 Win Api and JOBOBJECT_CPU_RATE_CONTROL_INFORMATION struct.
My bigger problem was to represent this structure in c# (uses "union"). Hopefully, I found a "mono" description of this structure.
To activate the Cpu limitation :
The sample below is fully functional.
I hope that's help.
Kind Regards
-Thierry-
Not in Windows. You can lower the process priority though, which will reduce the likelihood that the problematic process will be scheduled on the CPU and interfere with other (presumably higher priority) applications. For instance, from http://dotnet-concepts-queries-interviews.blogspot.com/2007/05/how-to-set-process-priority-in-net.html:
Keep in mind, if you don't have anything else running on the box, you probably want this process to consume all of the available CPU.
You can also set the CPU affinity if it is on a multi-processor box, limiting the processing to certain cores and leaving others free for other applications. Generally the OS does a good job of scheduling application threads though, so setting the process priority is likely to have a better overall result. See How Can I Set Processor Affinity in .NET?