Results 1 to 2 of 2

Thread: QProcess won’t terminate immediately in a forked process

  1. #1
    Join Date
    Feb 2013
    Posts
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default 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:
    Qt Code:
    1. // start player as daemon
    2. pid_t pid, sid;
    3. // fork off parent process
    4. pid = fork();
    5. if (pid < 0) {
    6. // fork failed
    7. fprintf(stderr, "Unable to fork daemon process.");
    8. exit(EXIT_FAILURE);
    9. }
    10. if (pid > 0) {
    11. // fork succeeded. terminate parent
    12. qDebug() << "Forking child (" << pid << ") succeeded. Terminating parent (" << getpid() << ").\n";
    13. exit(EXIT_SUCCESS);
    14. }
    15.  
    16. // child continues...
    17. umask(0);
    18. // start new session
    19. sid = setsid();
    20. if (sid < 0) {
    21. fprintf(stderr, "Unable to start new session.");
    22. exit(EXIT_FAILURE);
    23. }
    To copy to clipboard, switch view to plain text mode 

    my QProcess is started:
    Qt Code:
    1. this->activePlayer = new QProcess(this);
    2. this->activePlayer->start(QString("mplayer"), this->playerArgs);
    3. this->activePlayer->waitForStarted();
    To copy to clipboard, switch view to plain text mode 
    and terminated
    Qt Code:
    1. kill(this->activePlayer->pid(), SIGTERM);
    2. this->activePlayer->waitForFinished();
    3. system("killall mplayer 2> /dev/null"); // kill all remaining videoplayer processes!
    4. delete this->activePlayer;
    To copy to clipboard, switch view to plain text mode 
    Instead of “kill”, I also tried here
    Qt Code:
    1. this->activePlayer->terminate();
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. this->activePlayer->kill();
    To copy to clipboard, switch view to plain text mode 

    same results! :-(

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess won’t terminate immediately in a forked process

    Quote Originally Posted by lederer View Post
    same results! :-(
    What results? It seems to me your process should end by itself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 18th July 2012, 14:33
  2. Replies: 0
    Last Post: 26th August 2010, 10:44
  3. Replies: 8
    Last Post: 29th June 2010, 07:10
  4. QProcess doesn't terminate
    By Bagstone in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2008, 00:43
  5. Replies: 4
    Last Post: 27th July 2006, 11:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.