admin管理员组文章数量:1125492
I want to be able to identify if code is running within Qemu, there is a custom OS image running on QEMU so there are not many third-party utilities available eg. dmidecode to verify the same.
Is there a reliable way to check the above using any linux commands?
pmap/dmidecode both were not identified.
ps -aux did not have any qemu process running as suggested by some users. Currently, I'm out of options.
I want to be able to identify if code is running within Qemu, there is a custom OS image running on QEMU so there are not many third-party utilities available eg. dmidecode to verify the same.
Is there a reliable way to check the above using any linux commands?
pmap/dmidecode both were not identified.
ps -aux did not have any qemu process running as suggested by some users. Currently, I'm out of options.
Share Improve this question asked 2 days ago Tanisha SaxenaTanisha Saxena 112 bronze badges New contributor Tanisha Saxena is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 3 |1 Answer
Reset to default 0Using the C language you could try with:
#include <stdio.h>
#include <string.h>
int isRunningInQemu() {
FILE *cpuinfo = fopen("/proc/cpuinfo", "r");
if (cpuinfo == NULL) {
perror("fopen failure.");
return 0;
}
char line[256];
while (fgets(line, sizeof(line), cpuinfo)) {
if (strstr(line, "QEMU")) {
fclose(cpuinfo);
return 1;
}
}
fclose(cpuinfo);
return 0;
}
int main() {
if (isRunningInQemu()) {
printf("Running inside QEMU emulator.\n");
} else {
printf("Not running inside QEMU emulator.\n");
}
return 0;
}
本文标签: linuxHow can I identify if the code is running inside QEMU EmulatorStack Overflow
版权声明:本文标题:linux - How can I identify if the code is running inside QEMU Emulator? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736627975a1945716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
grep -q QEMU /proc/cpuinfo && echo QEMU || echo Not QEMU
– Philippe Commented yesterdaygrep -qi "QEMU" /sys/class/dmi/id/product_name
? – Philippe Commented yesterday