Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a Process is Running or Not

Tags:

qt

I am starting a process using the below code

 QProcess* process = new QProcess();
 process->start(Path);

The start method will start a third party application.

If the process is already running, I should not call process->start(Path) again.

The process pointer is private member of the class.

like image 673
TimeRun Cit Avatar asked Dec 10 '22 00:12

TimeRun Cit


1 Answers

From the docs for QProcess ...

There are at least 3 ways to check if a QProcess instance is running.

QProcess.pid() : If its running, the pid will be > 0

QProcess.state() : Check it again the ProcessState enum to see if its QProcess::NotRunning

QProcess.atEnd() : Its not running if this is true

If any of these are not working as you would expect, then you will need to post a specific case of that example.

like image 102
jdi Avatar answered Apr 29 '23 00:04

jdi