Find out if the OS is running in a virtual environment
If running as root to use dmidecode
does not work for your needs, try lspci
:
$ /sbin/lspci |grep VMware
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
You (probably) don't particularly care what the virtual video card is, but you're not going to find that answer in real hardware, so you can use it as an identifier.
I usually use dmidecode
to do exactly that (though you need to have root access to do that). Look for the "BIOS Information" section, it will usually have the "Vendor" or "Version" fields set to "VMWare", "VirtualBox" or something similar.
You don't say what approach you're using to do this but you can certainly do it in C.