22 #include <QTextStream>
23 #include <QApplication>
31 return (qint64)GetCurrentProcessId();
33 return (qint64)getpid();
43 if (procList.contains(pid)) {
45 QString exeFile = procList.value(pid);
46 QString thisExe = QFileInfo(QApplication::applicationFilePath()).fileName();
47 return (exeFile.toLower() == thisExe.toLower());
52 if (kill((pid_t)pid, 0) < 0) {
53 return (errno != ESRCH);
64 QDir pidFileDir = QFileInfo(pidFileName).absoluteDir();
65 if (!pidFileDir.exists()) {
66 pidFileDir.mkpath(QDir::convertSeparators(pidFileDir.absolutePath()));
70 QFile pidfile(pidFileName);
71 if (!pidfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
72 return err(errmsg, pidfile.errorString());
76 QTextStream pidstream(&pidfile);
89 QFile pidfile(pidFileName);
90 if (!pidfile.exists()) {
93 if (!pidfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
95 *errmsg = pidfile.errorString();
101 QTextStream pidstream(&pidfile);
106 QHash<qint64, QString>
109 #if defined(Q_OS_WIN32)
112 return QHash<qint64, QString>();
119 #if defined(Q_OS_WIN32)
120 HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE,
121 static_cast<DWORD>(pid));
122 if (hProcess == NULL)
125 BOOL ret = TerminateProcess(hProcess, 0);
126 CloseHandle(hProcess);
128 return (ret != FALSE);