Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Killing the process

Killing the process

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 6 Posters 0 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.
  • S Offline
    S Offline
    stanlymt
    wrote on last edited by
    #1

    How will I kill all the spawned processes of my application? I dont want to kill my main application, but only the all other processes spawned by my main application? Is there any articles related to this? Thanks, Stanly

    N S T 3 Replies Last reply
    0
    • S stanlymt

      How will I kill all the spawned processes of my application? I dont want to kill my main application, but only the all other processes spawned by my main application? Is there any articles related to this? Thanks, Stanly

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      When u spawn a process using CreateProcess() u will get the preocss handle of the new process. Store that handle in a Vaiable. So when u want to Kill the spawned preocess, call TerminateProcess() with that handle. nave

      S 1 Reply Last reply
      0
      • N Naveen

        When u spawn a process using CreateProcess() u will get the preocss handle of the new process. Store that handle in a Vaiable. So when u want to Kill the spawned preocess, call TerminateProcess() with that handle. nave

        S Offline
        S Offline
        stanlymt
        wrote on last edited by
        #3

        The problem with me is that, I'm spawning many process. One process my spawn other process. So my spawned process is having many other spawns. But when I'm terminating the main spawned process, only that process is terminated, not the child processes. I want to implement Kill Process Tree function for my child processes. Thanks, Stanly

        N 1 Reply Last reply
        0
        • S stanlymt

          The problem with me is that, I'm spawning many process. One process my spawn other process. So my spawned process is having many other spawns. But when I'm terminating the main spawned process, only that process is terminated, not the child processes. I want to implement Kill Process Tree function for my child processes. Thanks, Stanly

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          if all the process u create have window( or create a message only window), u can send the WM_CLOSE message to all the child process. When a WM_CLOSE message arrives, let it send the WM_CLOSE message to its child process and so on... nave

          S 1 Reply Last reply
          0
          • N Naveen

            if all the process u create have window( or create a message only window), u can send the WM_CLOSE message to all the child process. When a WM_CLOSE message arrives, let it send the WM_CLOSE message to its child process and so on... nave

            S Offline
            S Offline
            stanlymt
            wrote on last edited by
            #5

            This solution won't work for me because I won't be able to keep track of all spawned windows/applications. Spawned application say MS SQL query analyzer is not created by me. So, that application may spawn other applications. I want to implement the function of Kill Process tree just like in Process Explorer by Mark Russinovich (www.sysinternals.com). Thanks, Stanly

            S D 2 Replies Last reply
            0
            • S stanlymt

              This solution won't work for me because I won't be able to keep track of all spawned windows/applications. Spawned application say MS SQL query analyzer is not created by me. So, that application may spawn other applications. I want to implement the function of Kill Process tree just like in Process Explorer by Mark Russinovich (www.sysinternals.com). Thanks, Stanly

              S Offline
              S Offline
              SilentSilent
              wrote on last edited by
              #6

              stanlymt wrote:

              This solution won't work for me because I won't be able to keep track of all spawned windows/applications. Spawned application say MS SQL query analyzer is not created by me. So, that application may spawn other applications.

              You are doomed!

              1 Reply Last reply
              0
              • S stanlymt

                How will I kill all the spawned processes of my application? I dont want to kill my main application, but only the all other processes spawned by my main application? Is there any articles related to this? Thanks, Stanly

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #7

                Terminating process, especially processes you didn't even write, is asking for trouble. Here's a quote from MSDN:  "The TerminateProcess function is used to unconditionally cause a process to exit. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used" The fact that terminating a process is not safe is obvious if you think about it: The process may be in the middle of doing something like updating a file and suddenly it's killed without getting a chance to do any cleanup. This could quite obviously lead to data corruption for example. TerminateProcess is meant as a last resort like when like you have to kill a misbehaving and non-responsive process with task manager. Steve

                1 Reply Last reply
                0
                • S stanlymt

                  This solution won't work for me because I won't be able to keep track of all spawned windows/applications. Spawned application say MS SQL query analyzer is not created by me. So, that application may spawn other applications. I want to implement the function of Kill Process tree just like in Process Explorer by Mark Russinovich (www.sysinternals.com). Thanks, Stanly

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Take a look at the Process32First()/Process32Next() pair.


                  "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                  "Judge not by the eye but by the heart." - Native American Proverb

                  1 Reply Last reply
                  0
                  • S stanlymt

                    How will I kill all the spawned processes of my application? I dont want to kill my main application, but only the all other processes spawned by my main application? Is there any articles related to this? Thanks, Stanly

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #9

                    stanlymt wrote:

                    How will I kill all the spawned processes of my application? I dont want to kill my main application, but only the all other processes spawned by my main application? Is there any articles related to this?

                    look at CreateToolhelp32Snapshot and related api:)

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups