0

I'm developing an application in Qt.

First, I created a QProcess object :

process = new QProcess(this);
// launching plink by script 
process->start(plinkLauncherScriptPath, arguments);

Script looks like this:

 @echo off
 echo y | "%~dp0/plink.exe" %1 -L %2

I get seesionID and everything seems ok, but the problem appears when I want to end this session and open a new one.

I try to kill process with :

 QString write = "0x01";               
 process->write(write.toLatin1());
 //  process->terminate(); i tried this too 
 process->close();
 //  process->kill();  i tried this too 

The process is killed, but PLINK.exe is still running (I see it in Windows task manager), and every new session creates another running instance.

From the application, I can only take pid of QProcess, not plink itself :

process->pid(); // here would be shown some id 0x875f50c8
process->processId(); // here would be shown some id 4936
process->close();
process->pid(); // here would be shown some id 0x0
process->processId(); // here would be shown some id 0

This code shows that QProcess is closed successfully, but plink still stays.

One option is to create another script which would kill all processes named "PLINK". It can look like this:

taskkill /im plink.exe

Unfortunately, by running it, I would kill all plink processes, even these ones which were launched by other programs.

Have you got any idea to solve this problem?

IAmInPLS
  • 4,051
  • 4
  • 24
  • 57
MyWay
  • 1,011
  • 2
  • 14
  • 35
  • https://forum.qt.io/topic/40449/kill-child-process-of-qprocess/5 ? – fghj Apr 13 '16 at 12:55
  • On Windows, processes don't have a meaningful parent-child-relationship. It is recorded by the system for informational purposes only. If you wish to kill an entire process tree, you have to manually search for all participating processes yourself. If you want to control a group of processes as a whole, use [Job Objects](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684161.aspx) instead. – IInspectable Apr 13 '16 at 13:23

0 Answers0