Discussion:
[Interest] The right way of using QProcess
Nuno Santos
2015-05-19 14:29:04 UTC
Permalink
Hi,

I’m calling the function below with a one second interval while my app is open. The functions executes the command “adb devices"

Is there any kind of limitation by the system by the number of calls? I think my system gets to a point where no more processes can be created: Chrome starts to hang, QtCreator isn’t able to do make, etc

static QString executeAdbCommand(QStringList arguments)
{
QProcess p;

//p.setReadChannel(QProcess::StandardError);

#ifdef Q_OS_MAC
p.start(QString("%1/adb").arg(QCoreApplication::applicationDirPath()), arguments);
#endif

#ifdef Q_OS_WIN
p.start("adb.exe", arguments);
#endif

//qDebug() << "Executing adb" << arguments;

if (!p.waitForStarted())
return "";

if (!p.waitForFinished())
return "";

QString output = p.readAll();

return output;
}

Nuno
Thiago Macieira
2015-05-19 14:58:32 UTC
Permalink
Hi,
I’m calling the function below with a one second interval while my app is
open. The functions executes the command “adb devices"
Is there any kind of limitation by the system by the number of calls? I
Chrome starts to hang, QtCreator isn’t able to do make, etc
Sounds like an attack of the zombies.... (no, really, there must be zombie
process left around)
static QString executeAdbCommand(QStringList arguments)
{
QProcess p;
//p.setReadChannel(QProcess::StandardError);
#ifdef Q_OS_MAC
p.start(QString("%1/adb").arg(QCoreApplication::applicationDirPath()),
arguments); #endif
#ifdef Q_OS_WIN
p.start("adb.exe", arguments);
#endif
//qDebug() << "Executing adb" << arguments;
if (!p.waitForStarted())
return "";
if (!p.waitForFinished())
return "";
QString output = p.readAll();
return output;
}
Don't return until waitForFinished() succeeds. That one guarantees wait() has
happened on the process, so we know there is no zombie left.

Is this Qt 5.4? Or are you already trying the 5.5 beta? The way we do wait()
has changed considerably in 5.5, so it might be worth testing the beta to see
if the problem also happens.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Nuno Santos
2015-05-19 15:12:20 UTC
Permalink
Thiago,

Thanks for your reply. Yes, this is 5.4.

I will investigate this further by doing some output on the waitForFinished return result.

I want to avoid installing another toolkit right now (lack of time and lack of space in my laptop) but I will consider it if the problems persists.

Regards,

Nuno Santos
Founder / CEO / CTO
www.imaginando.pt
+351 91 621 69 62
Post by Thiago Macieira
Post by Nuno Santos
Hi,
I’m calling the function below with a one second interval while my app is
open. The functions executes the command “adb devices"
Is there any kind of limitation by the system by the number of calls? I
Chrome starts to hang, QtCreator isn’t able to do make, etc
Sounds like an attack of the zombies.... (no, really, there must be zombie
process left around)
Post by Nuno Santos
static QString executeAdbCommand(QStringList arguments)
{
QProcess p;
//p.setReadChannel(QProcess::StandardError);
#ifdef Q_OS_MAC
p.start(QString("%1/adb").arg(QCoreApplication::applicationDirPath()),
arguments); #endif
#ifdef Q_OS_WIN
p.start("adb.exe", arguments);
#endif
//qDebug() << "Executing adb" << arguments;
if (!p.waitForStarted())
return "";
if (!p.waitForFinished())
return "";
QString output = p.readAll();
return output;
}
Don't return until waitForFinished() succeeds. That one guarantees wait() has
happened on the process, so we know there is no zombie left.
Is this Qt 5.4? Or are you already trying the 5.5 beta? The way we do wait()
has changed considerably in 5.5, so it might be worth testing the beta to see
if the problem also happens.
--
Thiago Macieira - thiago.macieira (AT) intel.com <http://intel.com/>
Software Architect - Intel Open Source Technology Center
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
Nuno Santos
2015-05-19 18:08:10 UTC
Permalink
Thiago,

I have found the cause. The command binary was not present on the directory thus, every call was being invoked without the program. It never started, it never ended.

You were right. It was a zombie attack.

Nuno Santos
Founder / CEO / CTO
www.imaginando.pt
+351 91 621 69 62
Post by Nuno Santos
Thiago,
Thanks for your reply. Yes, this is 5.4.
I will investigate this further by doing some output on the waitForFinished return result.
I want to avoid installing another toolkit right now (lack of time and lack of space in my laptop) but I will consider it if the problems persists.
Regards,
Nuno Santos
Founder / CEO / CTO
www.imaginando.pt <http://www.imaginando.pt/>
+351 91 621 69 62
Post by Thiago Macieira
Post by Nuno Santos
Hi,
I’m calling the function below with a one second interval while my app is
open. The functions executes the command “adb devices"
Is there any kind of limitation by the system by the number of calls? I
Chrome starts to hang, QtCreator isn’t able to do make, etc
Sounds like an attack of the zombies.... (no, really, there must be zombie
process left around)
Post by Nuno Santos
static QString executeAdbCommand(QStringList arguments)
{
QProcess p;
//p.setReadChannel(QProcess::StandardError);
#ifdef Q_OS_MAC
p.start(QString("%1/adb").arg(QCoreApplication::applicationDirPath()),
arguments); #endif
#ifdef Q_OS_WIN
p.start("adb.exe", arguments);
#endif
//qDebug() << "Executing adb" << arguments;
if (!p.waitForStarted())
return "";
if (!p.waitForFinished())
return "";
QString output = p.readAll();
return output;
}
Don't return until waitForFinished() succeeds. That one guarantees wait() has
happened on the process, so we know there is no zombie left.
Is this Qt 5.4? Or are you already trying the 5.5 beta? The way we do wait()
has changed considerably in 5.5, so it might be worth testing the beta to see
if the problem also happens.
--
Thiago Macieira - thiago.macieira (AT) intel.com <http://intel.com/>
Software Architect - Intel Open Source Technology Center
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Loading...