Kill orphan processes

This is a discussion on Kill orphan processes within the Windows Programming forums, part of the Platform Specific Boards category; Hello, My program launch an aplication, ie. called APL.exe. Also APL.exe launch console applications CON1.exe and CON2.exe. My application can ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    145

    Kill orphan processes

    Hello,

    My program launch an aplication, ie. called APL.exe. Also APL.exe launch console applications CON1.exe and CON2.exe.

    My application can be launched twice in the same machine, so there could be two instances of CON1.exe and CON2.exe.

    Sametimes, APL.exe exits, but CON1.exe and CON2.exe for that proccess remain without killing, so they are orphan. It is no often but it happens.

    I need a method to kill CON1.exe and CON2.exe with are orphan, as the other CON1.exe and CON2.exe are running under a running instance of APL.exe.

    Are there any way to do this?

    thx in advance

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    How are these applications launched, and do you have any control over their source code?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    145
    Quote Originally Posted by matsp View Post
    How are these applications launched, and do you have any control over their source code?

    --
    Mats
    APL.exe is launched by me. CON1.exe and CON2.exe are launched by apl.exe in a no-windows state. It looks is proccess intercomunication via stdin and stdout.

    I dont have any control over source code of them.

    I suppose this can be done, because process explorer of sysinternal show tree dependences of processes, and show the orphans. If this tool is capable of recognize them then must be a way to do it.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There is a way to do that, but procexp uses internal data structures [guess why the company is called "sysINTERNALs"?], so you may not be able to use that.

    Not sure I have a solution.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    You can build a process tree using the data returned by CreateToolHelp32Snapshot and Process32(First/Next), specifically the th32ParentProcessID and th32ProcessID members of the PROCESSENTRY32 struct.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    Quote Originally Posted by Kempelen View Post
    I suppose this can be done, because process explorer of sysinternal show tree dependences of processes, and show the orphans. If this tool is capable of recognize them then must be a way to do it.
    Yes, it's even a Win32 FAQ (since Win95)... see Google Groups, Win32

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 05-27-2009, 12:26 PM
  2. How to kill a dragon with various programming languages
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-01-2007, 12:13 PM
  3. using a signal handler to kill processes
    By dinjas in forum C Programming
    Replies: 2
    Last Post: 03-16-2005, 11:58 AM
  4. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-27-2005, 11:59 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21