Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to close the subroutine of the program started by qprocess?
Forum Updated to NodeBB v4.3 + New Features

How to close the subroutine of the program started by qprocess?

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 6 Posters 6.1k Views 1 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.
  • J jiaming
    2 Mar 2021, 08:49

    My program runs on Ubuntu

    J Offline
    J Offline
    JonB
    wrote on 2 Mar 2021, 08:53 last edited by JonB 3 Feb 2021, 08:59
    #11

    @jiaming

    My program runs on Ubuntu

    And so? As I & @Christian-Ehrlicher have said, you cannot use this to kill a "sub-sub-process". You don't know the PID of the process you want to kill.

    Can you please take the time to address what @Christian-Ehrlicher wrote earlier:

    Then fix A so it properly shuts down B

    [Under Linux you could try using pkill to kill all B processes, but I really wouldn't recommend it....]

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jiaming
      wrote on 2 Mar 2021, 09:04 last edited by
      #12

      I forgot to say that if A is opened in a terminal, B will also be closed when using Ctrl+C to close. What I am looking for is a method similar to sending a Ctrl+C signal.

      J J 2 Replies Last reply 2 Mar 2021, 09:52
      0
      • J jiaming
        2 Mar 2021, 09:04

        I forgot to say that if A is opened in a terminal, B will also be closed when using Ctrl+C to close. What I am looking for is a method similar to sending a Ctrl+C signal.

        J Offline
        J Offline
        JonB
        wrote on 2 Mar 2021, 09:52 last edited by JonB 3 Feb 2021, 09:52
        #13

        @jiaming
        Use Linux man 2 kill call: kill(pid_of_A, SIGINT). But I doubt it will work from here.

        It's nice to see that you ignore every suggestion we make.... Best of luck.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jiaming
          wrote on 2 Mar 2021, 11:32 last edited by
          #14

          The main reason is that I didn't write A and B programs. They have formed a good system. It's troublesome for me to change them. It's better to have a simpler method.

          I found that PPID of B is 1......

          I'm sorry for the trouble.

          J J 3 Replies Last reply 2 Mar 2021, 11:54
          0
          • J jiaming
            2 Mar 2021, 11:32

            The main reason is that I didn't write A and B programs. They have formed a good system. It's troublesome for me to change them. It's better to have a simpler method.

            I found that PPID of B is 1......

            I'm sorry for the trouble.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 2 Mar 2021, 11:54 last edited by
            #15

            @jiaming said in How to close the subroutine of the program started by qprocess?:

            I found that PPID of B is 1

            You need PID if you want to kill it...

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

            1 Reply Last reply
            0
            • J jiaming
              2 Mar 2021, 11:32

              The main reason is that I didn't write A and B programs. They have formed a good system. It's troublesome for me to change them. It's better to have a simpler method.

              I found that PPID of B is 1......

              I'm sorry for the trouble.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 2 Mar 2021, 12:03 last edited by
              #16

              @jiaming You could try to get PID from B using PID from A, see https://stackoverflow.com/questions/17743879/how-to-get-child-process-from-parent-process

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

              1 Reply Last reply
              0
              • J jiaming
                2 Mar 2021, 11:32

                The main reason is that I didn't write A and B programs. They have formed a good system. It's troublesome for me to change them. It's better to have a simpler method.

                I found that PPID of B is 1......

                I'm sorry for the trouble.

                J Offline
                J Offline
                JonB
                wrote on 2 Mar 2021, 12:36 last edited by JonB 3 Feb 2021, 12:38
                #17

                @jiaming said in How to close the subroutine of the program started by qprocess?:

                I found that PPID of B is 1......

                Which is why I said I do not think that sending a SIGINT to the parent (A) will have any effect on B...!

                A process ID value of 1 indicates that there is no parent process associated with the [...] process."

                1 Reply Last reply
                1
                • J jiaming
                  2 Mar 2021, 09:04

                  I forgot to say that if A is opened in a terminal, B will also be closed when using Ctrl+C to close. What I am looking for is a method similar to sending a Ctrl+C signal.

                  J Offline
                  J Offline
                  JoeCFD
                  wrote on 2 Mar 2021, 20:39 last edited by JoeCFD 3 Feb 2021, 20:54
                  #18

                  @jiaming kill( m_process->pid(), SIGINT ); <==this does what you need. You need somehow to find the pid of B.
                  std::string pid_str = exec( "pidof B" ); exec is defined in the post above and "pidof" is a linux command to find process id.
                  if( !pid_str.empty() ) {
                  int pid = std::stoi( pid_str );
                  kill( pid, SIGINT );
                  }

                  J 1 Reply Last reply 2 Mar 2021, 20:49
                  0
                  • J JoeCFD
                    2 Mar 2021, 20:39

                    @jiaming kill( m_process->pid(), SIGINT ); <==this does what you need. You need somehow to find the pid of B.
                    std::string pid_str = exec( "pidof B" ); exec is defined in the post above and "pidof" is a linux command to find process id.
                    if( !pid_str.empty() ) {
                    int pid = std::stoi( pid_str );
                    kill( pid, SIGINT );
                    }

                    J Offline
                    J Offline
                    JonB
                    wrote on 2 Mar 2021, 20:49 last edited by
                    #19

                    @JoeCFD said in How to close the subroutine of the program started by qprocess?:

                    You need somehow to find the pid of B.

                    But he doesn't know the PID of B.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JoeCFD
                      wrote on 2 Mar 2021, 21:03 last edited by
                      #20

                      Be aware that Control + C ( kill( pid, SIGINT ); ) may not kill your process all the time.
                      exec( "kill -9 pid" ) will be very clean.

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        Kent-Dorfman
                        wrote on 3 Mar 2021, 03:31 last edited by
                        #21

                        Nothing original to add, but I recommend all participants in this thread read http://morningcoffee.io/killing-a-process-and-all-of-its-descendants.html as he does a fair job explaining the relationships in POSIX environments.

                        I light my way forward with the fires of all the bridges I've burned behind me.

                        J 1 Reply Last reply 3 Mar 2021, 17:20
                        3
                        • K Kent-Dorfman
                          3 Mar 2021, 03:31

                          Nothing original to add, but I recommend all participants in this thread read http://morningcoffee.io/killing-a-process-and-all-of-its-descendants.html as he does a fair job explaining the relationships in POSIX environments.

                          J Offline
                          J Offline
                          JoeCFD
                          wrote on 3 Mar 2021, 17:20 last edited by
                          #22

                          @Kent-Dorfman thanks for sharing.

                          1 Reply Last reply
                          0

                          20/22

                          2 Mar 2021, 21:03

                          • Login

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