我想用C语言开发一个函数来进行一些处理,但这取决于chrome进程的状态。所以如果chrome正在运行,我应该杀死该进程以使程序正确执行
If(chrome is running )
system("taskkill /IM chrome.exe /F");
Operation 1
operation 2
..........
那么我如何翻译 c 中的 if(chrome is running ) 行 我使用 Windows
最佳答案
是的,我们可以。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
chrome_is_running() {
char buf[BUFSIZ];
int r = system("tasklist /FI \"IMAGENAME eq chrome.exe\" > .out");
FILE *fp = fopen(".out", "r");
int found = 0;
while (fgets(buf, sizeof(buf), fp)) {
if (strncasecmp(buf, "chrome.exe", 10) == 0) {
found = 1;
break;
}
}
unlink(".out");
return found;
}
int
main(int argc, char* argv[]) {
if (chrome_is_running())
system("taskkill /F /IM chrome.exe");
return 0;
}
关于c - 使用 C 程序验证 chrome 是否正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44806226/