Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QProcess can not be terminated.

QProcess can not be terminated.

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 5 Posters 4.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Nan.JiaoN Offline
    Nan.JiaoN Offline
    Nan.Jiao
    wrote on last edited by Nan.Jiao
    #1

    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

    kshegunovK 1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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)."

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Nan.JiaoN Offline
        Nan.JiaoN Offline
        Nan.Jiao
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • Nan.JiaoN Nan.Jiao

          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

          D Offline
          D Offline
          Devopia53
          wrote on last edited by Devopia53
          #4

          @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.

          1 Reply Last reply
          0
          • Nan.JiaoN Offline
            Nan.JiaoN Offline
            Nan.Jiao
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • Nan.JiaoN Nan.Jiao

              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

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @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.

              Read and abide by the Qt Code of Conduct

              Nan.JiaoN 1 Reply Last reply
              0
              • kshegunovK kshegunov

                @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.

                Nan.JiaoN Offline
                Nan.JiaoN Offline
                Nan.Jiao
                wrote on last edited by Nan.Jiao
                #7

                @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

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

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

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved