QProcess can not be terminated.



  • Hello all,
    I have met a terminate problem under Qt5.5 when call qprocess to launch a 'hostapd' or 'dnsmasq' command.
    showing a test widget with 'exit' button over main window and start process as below:
    m_prcs = new QProcess();
    list << "/rtl_hostapd.conf-nopassword" << "-d";
    m_prcs->start("hostapd",list);

    click 'exit' button back to the main window while executing below:
    m_prcs->terminate();

    But the 'hostapd' process is not terminated at all.

    The terminate() will send SIGTERM which is necessary for stopping 'hostapd'.

    There might be a correct way to do it, could some one help me with this , it will be very appreciated.

    Best Regards,
    Nan


  • Moderators

    You should check the output of the process after calling terminate(). Maybe it waits for user input?
    From the documentation:
    "The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc)."



  • Hello jsulm,

    Thanks for your reply. I follow your way and output the debug message.
    After calling terminate() , it does not output any thing. Also I put waitForFinished(5000) or even longer time out, the launched command never disappear from ps list.

    I have tried further with system("hostapd") instead of qprocess.
    There is one thing a little strange in main.cpp:

    system("hostapd -B /rtl_hostapd.conf-nopassword");
    QGuiApplication a(argc, argv);
    ...
    Then kill $PID of hostapd can terminate the hostapd.

    BUT: put system call like below:
    QGuiApplication a(argc, argv);
    system("hostapd -B /rtl_hostapd.conf-nopassword");
    ...
    kill $PID of hostapd can not terminate any more.

    I have no idea about this.

    Best Regards,
    Nan



  • @Nan.Jiao

    Have you ever used m_prcs->kill()?

    void QProcess::kill()
    Kills the current process, causing it to exit immediately.
    On Windows, kill() uses TerminateProcess, and on Unix and OS X, the SIGKILL signal is sent to the process.



  • Thank you for reply.

    QProcess:kill() can not terminate the executed 'hostapd' properly. By calling QProcess::kill(), the hostapd is killed , but the status of wifi driver is not reset. It is still broadcasting untill get a 'SIGTERM'.
    That is why I need a SIGTERM which could clear up everything which related to 'hostapd'.

    Before this line ' QCoreApplication a(argc, argv); ' in main.cpp , I can launch and terminate it without any problems. But launching after that line, I failed all the time. I do not know if there are some rights , ppid or gpid problems.

    Best Regards,
    Nan Jiao


  • Qt Champions 2016

    @Nan.Jiao
    Your problem is you're trying to manage a daemon in a very unusual way. On *nix systems the deamon will start, fork itself to detach the process from the terminal and then exit. So QProcess is not suited for such things. Not to mention there's a whole array of init scripts involved. You should rather read up on how your distribution manages daemons and use its "recommended way" of doing such things.
    What is the Linux you're using?

    The terminate() will send SIGTERM which is necessary for stopping 'hostapd'.

    It will send a SIGTERM to a process that's (probably) not running. And even if it were the correct process, daemons (should) intercept the SIGTERM signal and may choose to ignore it.

    QProcess:kill() can not terminate the executed 'hostapd' properly. By calling QProcess::kill(), the hostapd is killed , but the status of wifi driver is not reset. It is still broadcasting untill get a 'SIGTERM'.

    Sure, that'd be the equivalent of meeting someone and when the conversation is over hitting their head with a hammer. It leaves the daemon no way to perform proper cleanup, no leeway to free global resources - locking primitives, files, no possibility to shut down the driver gracefully and so on ...

    Kind regards.



  • @kshegunov
    The app is running on a Embedded device which is only a pure-linux with versoin 3.4.
    Before I had a qt4 version of this app, it was mainly using system("") and doing the same thing without any problems. Now for new futures of QML, I decided moving to Qt5. By switching off/on wifi module , I need qt to start or stop some basic services. Is there a good way to do it instead of using QProcess?

    Best Regards,
    Nan Jiao


  • Lifetime Qt Champion

    Hi,

    Does your distribution provide a service handling facility ? e.g. through the service command


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.