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. Kill child process on crash
QtWS25 Last Chance

Kill child process on crash

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 8.7k Views
  • 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 Offline
    J Offline
    Jakob Schou
    wrote on last edited by
    #1

    Is there a way to ensure that child processes created with QProcess are killed if the main process dies?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You could subclass QProcess and give it a new destructor. In the destructor, you check if the process is still running, and if it is, invoke QProcess::kill() on it.

      It all depends on how your main process died though. If the process suddenly terminates, there is no way to guarantee that destructor code will run at all. I don't know if there are other ways.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jakob Schou
        wrote on last edited by
        #3

        I am trying to address the situation where my main process crashes.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yshurik
          wrote on last edited by
          #4

          I guess this is question about Windows platform. On Unixes if you kill QProcess then also all its children will die. On Windows if you kill QProcess - its children keep living. I had to implement custom code using WinAPI to kill also all nested children in such case for win32 platform to have same behavior as on Unixes.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            yshurik, would you mind telling us how you did that? Did you integrate it into QProcess, or did you use some other method?

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yshurik
              wrote on last edited by
              #6

              Well, I can paste such code, but it is up to you to find correct place for invoking it - I had little different case:

              Invoke:
              @
              @

              Code to kill nested children
              @
              @

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                yshurik
                wrote on last edited by
                #7

                [quote author="Andre" date="1305291854"]yshurik, would you mind telling us how you did that? Did you integrate it into QProcess, or did you use some other method?[/quote]

                It was in my class - inherited from QProcess

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  Thanks for sharing!

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jakob Schou
                    wrote on last edited by
                    #9

                    I am running windows, mac and linux and none of the platforms seems to kill the child process. I call it a "child process" only because it is started using QProcess from my main process. Could it be that I miss a flag or something to actually make it a "nested child" process?

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #10

                      The integration does not help, if the master process dies.

                      It depends, how it dies, whether you can do some stuff or not.
                      If it is by exception (perhaps structured exception), they can be caught and the cleanup can be done.

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #11

                        Well... you could of course create some kind of monitoring process to do the cleanup for you in case the main process dies, but I think that is overkill.

                        It would be way better to avoid the crash in the first place ;-)

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          giesbert
                          wrote on last edited by
                          #12

                          [quote author="Andre" date="1305296276"]Well... you could of course create some kind of monitoring process to do the cleanup for you in case the main process dies, but I think that is overkill. [/quote]

                          You mean creating a process that check the processes state to cleanup children... ok, also a solution. Here in our software we such stuff but it's a huge product with partly customer apps also running as childs...

                          Nokia Certified Qt Specialist.
                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                          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