Guest OS in VirtualBox using more cores than allocated

78 views Asked by At

I was doing an experiment in VirtualBox. This is my setup.

Experiment Setup

I ran a simple code in the Guest OS

# include <stdio.h>
# include <stdlib.h>

int main()
{
    while(1)
    {
        int * p = (int *)malloc(sizeof(int));
    }

    return 0;
}

I saw that there were simultaneous spikes in all 4 cores of the host OS.

CPU Usage spikes in 4 cores instead of 1

I thought the guest OS is supposed to use a single core. What am I doing wrong or is this behaviour normal (If so, then why)?

PS : My core setup enter image description here

1

There are 1 answers

2
thor On BEST ANSWER

My guess is that while your code only takes one core, your program when executed can be switched into and out of context on different cores during the execution by the operating system. That's why you see all cores used, but the spikes occur at different times. (But this make take a more accurate measurement than looking at the resource monitor).