Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

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.

Thank you

share|improve this question
1  
It has to do with the OS is time slicing, and may reserve a small potion to accept interupts. Different priorities, different cpus (multi-core?), and even compiler flags can have an affect. –  hydroparadise Sep 27 '12 at 14:17
    
if CPU usage reached 100%, would the system crash? –  ostri Sep 27 '12 at 14:24
2  
I'm slightly surprised the compiler didn't optimize away all the code. The code is functionally identical to void main(){} isn't it? I would expect maxint to be reached almost instantly, presumably integer overflow is not regarded as noteworthy by your C compiler. –  RedGrittyBrick Sep 27 '12 at 14:26
    
@ostri: No. operating systems have higher priority than apps and (on modern mass-market CPUs) run in a privileged CPU state that gives them control over runaway apps (in theory anyway). –  RedGrittyBrick Sep 27 '12 at 14:28
    
@RedGrittyBrick Think your comment/question would be more interesting for the SO. And isn't integer overflow more to do with CPU instructions? Think MMX –  hydroparadise Sep 27 '12 at 14:29

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.