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?

3
  • 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
    Commented Sep 27, 2012 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
    Commented Sep 28, 2012 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
    Commented Sep 30, 2012 at 21:13

1 Answer 1

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .