Skip to content

Warn when killing a program with no Job Object of its own may leave something running - #134

Merged
HalRiveria merged 3 commits into
mainfrom
fix/no-tree-kill-warning
Dec 3, 2026
Merged

HalRiveria merged 3 commits into
mainfrom
fix/no-tree-kill-warning

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong

Some programs have no Job Object of their own: Windows refused one at the start, or the kit runs in NoJob mode. Killing one of them for its time limit, or in an abort's force-stop, goes to taskkill /T, which misses a child whose parent has already exited. The kill still counted as complete, with no warning.

  • Stop-PkProgramTree returned Killed when there was no tree job to check.
  • The force-stop only checked programs that had a tree job.

#133 added a warning only for a program whose Job Object Windows won't end. The README only mentioned the missed child for that case too.

What changed

  • A program killed without its own Job Object now gets the warning, once per session: the time-limit kill, the force-stop and Invoke-PkProcessWithTimeout's time limit. The warning names the process and why it was killed.
  • The warning shares -KillTreeOnExit's once-per-session check for a program with no Job Object of its own, so only one of the two warnings shows.
  • The force-stop only warns about a program that its kill actually ended. If the kill failed, Invoke-PkProcessWithTimeout's cleanup doesn't warn a second time, since its error already says the program may still be running.
  • When a failed start had to kill a program that was still running and had no Job Object of its own, the error now says what it started may still be running, instead of "so it was stopped".
  • README:
    • The note on killing a program's tree now covers a program without its own Job Object.
    • The -KillTreeOnExit paragraph says its warnings don't repeat once a kill has warned about the same cause.

No C# change.

How it was tested

Seven new assertions:

  • Section BJ (six): Check a killed program's tree job too, and warn when Windows won't end it #133's orphan tree. A program runs on, while its child starts a tagged ping through a .cmd file and exits at once. The tree is killed through the dispatcher's time limit, an abort's force-stop and Invoke-PkProcessWithTimeout's time limit. Each kill runs with TestNoTreeJob and with TestRefuseTreeJob. Each case expects the ping to be left running and exactly one warning saying the program has no Job Object of its own.
  • Section AW (one): a failed start whose program is still running when it's killed, with TestNoTreeJob.

Before the fix (main's kit with the new harness), on Windows PowerShell 5.1 and PowerShell 7 alike:

  [FAIL] a failed start that kills a program with no tree job says what may still be running (1 left running, error: ... so it was stopped.)
  [FAIL] a time-limit kill of a program with no tree job (TestNoTreeJob) says what may still be running, once (pings left 1, 0 warning(s): )
  [FAIL] a time-limit kill of a program with no tree job (TestRefuseTreeJob) says what may still be running, once (pings left 1, 0 warning(s): )
  [FAIL] an abort's force-stop of a program with no tree job (TestNoTreeJob) says what may still be running, once (pings left 1, 0 warning(s): )
  [FAIL] an abort's force-stop of a program with no tree job (TestRefuseTreeJob) says what may still be running, once (pings left 1, 0 warning(s): )
  [FAIL] Invoke-PkProcessWithTimeout's limit of a program with no tree job (TestNoTreeJob) says what may still be running, once (pings left 1, 0 warning(s): )
  [FAIL] Invoke-PkProcessWithTimeout's limit of a program with no tree job (TestRefuseTreeJob) says what may still be running, once (pings left 1, 0 warning(s): )
7 FAILED, 65 passed

After: the full harness passes on Windows PowerShell 5.1 and PowerShell 7 (819 assertions each).

@HalRiveria
HalRiveria merged commit 0588d47 into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/no-tree-kill-warning branch December 3, 2026 23:23
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