You are not logged in.

selmi

Beginner

  • "selmi" is male
  • "selmi" started this thread

Posts: 27

Location: Košice, Slovak Republic

Occupation: Programmer (PalmOS, Android, currently starting with Qt)

  • Send private message

1

Wednesday, March 24th 2010, 6:25pm

QProcess::kill kills launched app but doesn't kill its children

did anyone noticed such thing?

i make

Source code

1
2
3
4
5
6
7
8
QMap<QString,QProcess *> map;
QProcess *process=new Qprocess();
process->start("command",parameters,QProcess::ReadOnly);
process->waitForStarted();
if(!process->waitForFinished(2000))
  map.insert(myprocessid,process)
else
  delete process;


---
and much much later i iterate through map, take process (QProcess *) and for all items do

Source code

1
2
3
 process->kill();
process->waitForFinished();
delete process;


if launched processes are bash scripts then kill kills the script, but leaves all applications it launched running....i may kill them manually from commandline or some process list tools, but qt behaves as if it was successfull, just doesn't do anything for real. any idea how to solve this?

any idea what could be reason?

This post has been edited 1 times, last edit by "selmi" (Mar 25th 2010, 8:21am)


selmi

Beginner

  • "selmi" is male
  • "selmi" started this thread

Posts: 27

Location: Košice, Slovak Republic

Occupation: Programmer (PalmOS, Android, currently starting with Qt)

  • Send private message

2

Thursday, March 25th 2010, 9:00am

ugly workaround, i inserted this before actual kill()

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifdef Q_OS_LINUX
    Q_PID pid=pid();
    QProcess killer;
    QStringList params;
    params << "--ppid";
    params << QString::number(pid);
    params << "-o";
    params << "pid";
    params << "--noheaders";
    killer.start("/bin/ps",params,QIODevice::ReadOnly);
    if(killer.waitForStarted(-1))
    {
        if(killer.waitForFinished(-1))
        {
            QByteArray temp=killer.readAllStandardOutput();
            QString str=QString::fromLocal8Bit(temp);
            QStringList list=str.split("\n");

            for(int i=0;i<list.size();i++)
            {
                if(!list.at(i).isEmpty())
                    ::kill(list.at(i).toInt(),SIGKILL);
            }
        }
    }
#endif


isn't there better way?