Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer

 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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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