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 of QProcess
Forum Updated to NodeBB v4.3 + New Features

Kill child process of QProcess

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 8.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.
  • M Offline
    M Offline
    moravas
    wrote on last edited by
    #1

    Hi Folks,

    I have a problem about the killing of child processes of a QProcess instance. The issue is the following:
    In my GUI appclication I have a QProcess instance, which deployed by a user interaction. The started process starts other child processes as well.
    When the user presses the button "Stop", I trigger the "kill" slot of the QProcess, so the process will be killed, but its chiled processes stay there (I check it in the Windows task manager).
    Does anybody have a tip, how can I kill the whole process tree?

    Regards,
    Norbert

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      The problem is that you kill the process but you do not shut off gracefully. The process does not have a chance to cleanup.
      You may want to try "terminate()":http://qt-project.org/doc/qt-5/qprocess.html#terminate instead. This slot tries to shut-down a process gracefully. However, it may not work for all processes started (e.g. command line processes).

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moravas
        wrote on last edited by
        #3

        Hi,

        yes, doesn't help me: my started processes are console applications.
        Is there any sollution to list the deployed chiled processes of my QProcess instance or any other solution?

        Regads,
        Norbert

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          Not that I am aware of.
          The OS would have to support this. Possibly you can use "sysinternals":http://technet.microsoft.com/en-us/sysinternals/bb896682 and do some significant wrapping around.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #5

            Are we talking about Windows here? Windows does not really have the concept of a process hierarchy, like Linux has. So killing the "parent" process, will not kill the "child" processes it has created. Still, you can find out by which process a specific process had been created. So if you which to kill all "child" processes of process XYZ, you will have to filter all running processes and then kill those that had been created by XYZ. This will require going down to the Win32 API. Use CreateToolhelp32Snapshot to create a snapshot and then iterate trough the process list via Process32First and Process32Next.

            See also:
            http://msdn.microsoft.com/en-us/library/windows/desktop/ms684839(v=vs.85).aspx

            The "th32ParentProcessID" field is what you are interested in ;-)

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            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