in reply to Re: Killing a process on Windows (Win32::Process question)
in thread Killing a process on Windows (Win32::Process question)

Windows doesn't track "sub"processes. Any started process is a peer to all others.

Since circa. Win2000, it can track related process groups--see Job objects and Win32::Job


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re^2: Killing a process on Windows (Win32::Process question)

Replies are listed 'Best First'.
Re^3: Killing a process on Windows (Win32::Process question)
by John M. Dlugosz (Monsignor) on May 13, 2009 at 16:11 UTC
    I know. But just starting a process doesn't automatically associate it with the parent. Process Explorer, which I highly recommend, highlights Jobs in a ochre. They are seldom used. I see trees of processes started by a project build, some programs such as Open Office, the virus checking system, and of course Explorer and the various command shells, and from using git. None of them use Job objects.

    —John

      But just starting a process doesn't automatically associate it with the parent.

      From the documentation that was available, that certainly used to be the case, indeed the MSDN used to shy away from using terms like "parent" and "child". Since Win2000 I wouldn't be so sure, although it does depend on what you mean by associate.

      The history of Win32 APIs to iterate through processes is checkered, there used to be at least two rival systems, or even browsing HKEY_PERFORMANCE_DATA. However from W2k there was this (code extract from an XS module):
      static int getppid(void) { HANDLE hToolSnapshot; PROCESSENTRY32 Pe32 = {0}; BOOL bResult; DWORD PID; DWORD PPID = 0; PID = GetCurrentProcessId (); hToolSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hToolSnapshot == INVALID_HANDLE_VALUE) { return 0; } Pe32.dwSize = sizeof(PROCESSENTRY32); bResult = Process32First(hToolSnapshot, &Pe32); if (!bResult) return 0; while ( Process32Next(hToolSnapshot, &Pe32) ) { if (Pe32.th32ProcessID == PID) { PPID = Pe32.th32ParentProcessID; break; } } /* Expected */ if (GetLastError() == ERROR_NO_MORE_FILES) { SetLastError(ERROR_SUCCESS); } return PPID; }
      Apologies for displaying a foreign language on this site.
        I also noticed in the perl source code for PP_system that it was doing its own associating, so it knew who to propagate the BREAK signal into. So, add to that processes that explicitly keep track of their (immediate) children.