Why does “while(true)” without “Thread.sleep” cause 100% CPU usage on Linux but not on Windows?

后端 未结 1 1490
情歌与酒
情歌与酒 2020-12-22 20:58

I have created a simple program in java:

public static void main(String[] args) throws InterruptedException {
    while (true) 
        ;
}

相关标签:
1条回答
  • 2020-12-22 21:09

    By default, top on Linux runs in so-called IRIX mode, while the Windows Task Manager does not. Let's say you have 4 cores:

    • With IRIX mode on, 1 fully utilized core is 100% and 4 cores are 400%.

    • With IRIX mode off, 1 fully utilized core is 25% and 4 cores are 100%.

    This means that by default, top on Linux will show an infinite loop as ~100% and Windows will show it as ~25%, and it means exactly the same thing.

    You can toggle IRIX mode while top is running with Shift+i. This will make the numbers match up.

    0 讨论(0)
提交回复
热议问题