简体   繁体   中英

How to to force a process to have high CPU

I have a service that monitors how much CPU a process is using and alarms when the process is above a certain threshold.

I need to test to see that the monitor is detecting that the service is using a large amount of CPU cycles.

Is there any way to force a process to show a high amount of CPU usage without having access to the source code on the process?

I would eventually like to have a testing application that could spike the CPU of any process.

If you are using multi core processor Use ThreadPool to spam threads. spam as number of processor should be enough to make cpu almost 100% load.

private static void Main()
{
    for (int i = 0; i < Environment.ProcessorCount; i++)
    {
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
    }

    Console.ReadLine();
}

static void ThreadProc(Object stateInfo)
{
    while (true)
    {
       // do something
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM