bool CommFunction::isProcessRunning(const QString &processName) { QProcess process; #ifdef WIN32 process.start("tasklist", QStringList() << "/FI" << "IMAGENAME eq " + processName); process.waitForFinished(); // 等待命令执行完毕 QString output = process.readAllStandardOutput(); return output.contains(processName, Qt::CaseInsensitive); #else // 使用pgrep命令查找进程ID process.execute("pgrep", QStringList() << "-f" << processName); process.waitForFinished(); // 等待命令执行完毕 QString output = process.readAllStandardOutput(); // 如果输出不为空,则说明进程存在 return !output.isEmpty(); #endif // WIN32 }
标签:Qt,process,window,名称,Linux,进程 From: https://www.cnblogs.com/bclshuai/p/18221734