kohsuke/winp — pull request #8 by bturner (2012-10-31 06:46:31+00:00)
Title: Issue 6: Fix recursive process killing

Premise:
Windows processes do not reset their PPIDs when they survive longer than their parent processes, meaning, through PID reuse, processes sometimes "inherit" children they didn't actually start

Solution:
- KillProcessTreeWinHelper is no longer recursive, and now only creates a single snapshot rather than one for each recursion
- The same snapshot is walked multiple times, gathering up the entire hierarchy of processes
- The root PID being killed is used to match PPIDs to find children
- Each child's PID is used to further match its children, iteratively
- When matching children, rather than assuming because a child's PPID matches another process's PID it really is that process's child, the child process's creation time is compared to the parent's
- If the child is created AT or AFTER the parent, it is assumed to be a real child, rather than one inherited through PID reuse
- If the child is created BEFORE the parent, it assumed to not be a real child and will not be killed

While testing this, I noticed that getting the command line failed pretty consistently under Windows 8 (I also verified that it appears to fail the majority of the time under Windows 7, too). Included is a slight change to have the environment variables are read in, allowing a partial read to be considered successful as long as _some_ bytes are read.
- Anecdotally, it appears sometimes the read size ends up being too large, resulting in partial reads where what was read is really all of the data available
- Modified TheTest.testGetCommandLine() to ignore any exceptions that are thrown since it iterates over every process running on the box and many of them fail (pull request #7)

Lastly, a few places where brace-on-next-line formatting was used have been reformatted to brace-on-same-line, since that appears to match the majority of the code. Additionally, added .gitignore to help ensure the compiled binaries and other Visual Studio files are not accidentally checked into the repository.