Can I detect whether a process is running on a virtual machine using any cloud platform and not on a local machine?
Hi,
We have looked into __cpuid. The __cpuid will give us four registers (EAX, EBX, ECX, EDX) values when we pass a function id and an array. Inside ECX 31st bit will let us know hypervisor bit is being set to true or not. That will lead us to know whether we are being running on a virtual machine or a local machine.
Inside this Wikipedia link please check the 31st bit of the table it clearly says it would be zero for physical machines.
I tried a program to know whether that bit value is true or false but, on both machines irrespective of virtual and physical this is set to be true.
#include <stdio.h>
#ifdef _WIN32
#include <intrin.h>
#endif
int isHypervisor(void)
{
#ifdef _WIN32
int cpuinfo[4];
__cpuid(cpuinfo, 1);
if (cpuinfo[2] >> 31 & 1)
return 1;
#endif
return 0;
}
int main(int argc, char** argv)
{
if (isHypervisor())
printf("Virtual machine: yes\n");
else
printf("Virtual machine: no\n");
return 0;
}
But how task manager is able to detect whether that is virtual machine or not? Can I know how can it be done?