Skip to content

Kill the whole process tree on overruns and abort force-stops - #15

Merged
HalRiveria merged 3 commits into
mainfrom
fix/kill-process-tree
Oct 28, 2026
Merged

HalRiveria merged 3 commits into
mainfrom
fix/kill-process-tree

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong. Two places still called Process.Kill(), which ends only the program itself:

  • Invoke-PkProcessWithTimeout, when a program overran or the run was aborted;
  • the dispatcher's force-stop after an abort.

If the program had started others (a .cmd wrapper, a tool with worker processes), they kept running and holding its output open until the script exited. The batch timeout from #9 already killed the whole tree; these didn't.

What changed. All of them now use Stop-PkProcessTree (taskkill /T, falling back to Kill()). The dispatcher calls are wrapped as before, since a custom starter's .Proc may not be a Process. The README's FAQ line about stopping programs says it includes anything they started.

Testing. Two new assertions start cmd /c ping and check by command line that no ping survives:

  • an Invoke-PkProcessWithTimeout overrun;
  • a batch force-stopped after an abort.

Both fail against main and pass here. 219 assertions pass on Windows PowerShell 5.1 and PowerShell 7.6. Merges cleanly with #13.

🤖 Generated with Claude Code

Invoke-PkProcessWithTimeout (overrun or abort) and the dispatcher's
force-stop after an abort called Process.Kill(), which ends only the
program itself. Anything it started kept running, holding its output
open, until the script exited. They now use Stop-PkProcessTree, like
the batch timeout already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The force-stop after an abort ran taskkill once per job, waiting for each
before the next, which added seconds with many programs still running.
Stop-PkProcessTree now takes several processes and kills all their trees
in one taskkill call; the dispatcher's force-stop and teardown paths use
that through Stop-PkJobProcesses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HalRiveria added a commit that referenced this pull request Oct 28, 2026
…cessTree

Brings in the process-tree kill changes and the global functions so the
help describes the behaviour they add: Stop-PkProcessTree takes several
programs, and Invoke-PkProcessWithTimeout / the dispatcher's force-stop
kill a program's children too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…artly fails

With several PIDs, taskkill exits non-zero if any one was already gone
(it exited a moment before, or was taken by another listed tree), even
though it killed the rest, so the call returned $false. It now counts
the call as having killed them if any listed process is gone afterwards.
The race itself can't be set up on demand in the harness; a new
assertion covers a parent and its child passed together.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria
HalRiveria merged commit 3c74d26 into main Oct 28, 2026
2 checks passed
@HalRiveria
HalRiveria deleted the fix/kill-process-tree branch October 28, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants