为什么起源过程在Qt-app中以僵尸身份开始。 Linux的

时间:2014-11-03 09:18:02

标签: c++ linux qt process zombie-process

我正在使用qt creator在linux上编写一个小应用程序。 当我启动我的应用程序时,我希望它执行一个shell命令。我正在使用QProcess这样:

int main(int argc, char *argv[])

    {
        MyApplication a(argc, argv);

        QProcess mapProc(&a);

        QString command;
        QStringList args;

        command = "java";
        args << "-jar" << "/home/$USER/MapServer/map.jar" << "localhost" << "9797" << "12123";

        mapProc.start(command, args);

        bool flag  = mapProc.waitForStarted();
        QProcess::ProcessState state = mapProc.state();

        qDebug() << mapProc.errorString();
        qDebug() << mapProc.pid();


    /*/////////////////
    some code
    /////////////////*/

        return a.exec();
    }

但是当我的应用程序启动时,请处理&#34; mapProc&#34;变成僵尸。为什么?我做错了什么?

1 个答案:

答案 0 :(得分:1)

$USERQProcess的效果不同。你需要通过/bin/sh -c "mycmd"来调用命令,如果你只是按照下面的指示进行正确的Qt方式,你需要更好。

尝试使用QStandardPaths,请写下:

QString homeLocation =
    QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
args << "-jar" << QString(homeLocation.first() + "/MapServer/map.jar")
     << "localhost" << "9797" << "12123";

而不是:

args << "-jar" << "/home/$USER/MapServer/map.jar"
     << "localhost" << "9797" << "12123";