Important: Please read the Qt Code of Conduct -

QProcess won't terminate immediately in a forked process

  • I have the following problem:

    I have a linux application, which can be either run as a standalone application or a service (forked).

    My application later starts another application (in this case, mplayer) using a QProcess.
    If I terminate my application, I first sent a SIGTERM to my sub process, wait for its termination and then delete my QProcess object and terminate my application. All this works fine, if I am in standalone mode.

    If I do the same in service mode, the QProcess will NOT terminate after I sent the SIGTERM, but the started process gots zombie.
    The result is that my application waits 30 seconds (even, if I do NOT add a "waitForFinished") until it kills the QProcess and terminates.

    My question now is:
    does anyone know, WHY QProcess cannot be terminated/killed, if the application is running in service mode, but can, if it is running normally?

    Thx for any help!!

    Some details:
    Service mode means:
    // start player as daemon
    pid_t pid, sid;
    // fork off parent process
    pid = fork();
    if (pid < 0) {
    // fork failed
    fprintf(stderr, "Unable to fork daemon process.");
    if (pid > 0) {
    // fork succeeded. terminate parent
    qDebug() << "Forking child (" << pid << ") succeeded. Terminating parent (" << getpid() << ").\n";

    // child continues...
    // start new session
    sid = setsid();
    if (sid < 0) {
        fprintf(stderr, "Unable to start new session.");


    my QProcess is started:
    this->activePlayer = new QProcess(this);
    this->activePlayer->start(QString("mplayer"), this->playerArgs);

    and terminated
    kill(this->activePlayer->pid(), SIGTERM);
    system("killall mplayer 2> /dev/null"); // kill all remaining videoplayer processes!
    delete this->activePlayer;

    Instead of "kill", I also tried here

    same results! :-(

  • Remove the 'exit' from your parent project. Just return.

    You shared your QApplication between both processes, only one can 'exit'.

Log in to reply