I want to write a program to keep my CPU Usage to 50%.How can I do it?
I just can't find the API I need to use.Anybody can help?
(PS: My OS is WINXP)

Lemme get this straight, you want to purposely cripple your machine so that no matter how much work you have to do, it will always take twice as long to do it.

Or are you asking why your program which contains "while(1)" is burning all the CPU time and you want to restrict that single program in some way?

Lemme get this straight, you want to purposely cripple your machine so that no matter how much work you have to do, it will always take twice as long to do it.

Or are you asking why your program which contains "while(1)" is burning all the CPU time and you want to restrict that single program in some way?

It's just a question from my interview!I don't know how the CPU usage is caculated by the OS,and what is its meaning. Can you help me? I get the hint is:

while(1)
{
  if(busy)i++;
  else
  //something to let CPU be idle that I don't know
}

I suppose that something is either Sleep() (MS-Windows) or sleep() (*nix) which will cause your program to get very little CPU time.

wait in a socket, write a client which pumps data faster than your server can process.

I don't think that is possible because I THINK the socket libraries will slow everything down to prevent that from happening.

This article has been dead for over six months. Start a new discussion instead.