I'm writing desktop application for windows in Qt.
I have name of 3 processes that if they are running I want to kill them in the begining of my application.
What the best way to do it?(get the status of process by using the process name, and kill it if it's open).
code example can help me a lot. Thanks!
a) Type the following command into the command prompt, to kill only the one Process, and press Enter Key. For Example - To kill Notepad, run the command as, taskkill /IM notepad.exe /F , where /F is used to kill the process forcefully.
You can use Qprocess for this purpose. At the start of your application,Do
Qprocess p;
p.start("pkill processname1");
p.waitForFinished();
p.start("pkill processname2");
p.waitForFinished();
p.start("pkill processname2");
p.waitForFinished();
Or you can use system call directly..
system("pkill processname1");
system("pkill processname2");
system("pkill processname3");
In Windows environment, you can use following commands to kill process
process -k “Process ID”
process -k “Process Name”
You can read more of these here.
Under Windows use taskkill command You can call it using
QProcess::execute("taskkill /im <processname> /f");
Or
system("taskkill /im <processname> /f");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With