2

I have a dual-core processor. I'm running two instances of the program below

void void main(){
    int i;
    while(1){
        i=i+1;
    }
}

I run TOP and CPU usage gets up to 97%, however it never reaches 100%, why doesn't it? CPU is supposed to be always busy running the two programs with no I/O operation.

How would the int overflow affect the memory?

Does TOP actually show all the CPU usage or is there a percentage of the CPU reserved only for the SO that is not shown there? Are there processes of the SO that are not shown there?

  • 97% is pretty much for such a program (since it will be in the first level CPU-cache with just a few assembler opcodes). Try to draw the square root of 2 instead... – Nils Sep 27 '12 at 20:49
  • still dont understand cpu should be at full usage because it is always doing arithmetic operations... maybe because is a pipe-lined superscalar processor? – ostri Sep 28 '12 at 13:09
  • an increment by one is a pretty boring operation for a CPU (even before pipelines were build into CPUs). So there will be time left to look for more interesting jobs. And yes - pipelining has to do something with it. – Nils Sep 30 '12 at 21:13
2
 why doesn't it? 

there is a concept of scheduling, further it also depends on number of core.On my system this program can't cause more than 13% cpu usage(until you don't write multi-core manipulation program).You can try some benchmarking tool and can see your top reporting upto 100% cpu usage.

How would the int overflow affect the memory?

After -231 your int i will have a value of 0 again.

  • In Linux, maxing out one core is 100% usage, 2 cores 200% usage, etc. – jordanm Sep 27 '12 at 22:21
  • what do you mean by sheduling? Does TOP show all the running processes and the true cpu usage? – ostri Sep 28 '12 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.