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! :-(