Skip to content

Use TerminateJobObject for Process.Kill(entireProcessTree: true) on Windows #126273

Closed as not planned

Description

@adamsitnik

As soon as #126107 is done, we are going to implement #13943 which is going to force us to use STARTUPINFOEX on Windows. This is then going to let us implement #101985 which will require using Job objects on Windows. This particular job will have to use JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, but I believe that we should go one step further and always create a new job when starting new Process with CreateProcess on Windows.

Then for processes started without UseShellExecute, Process.Kill(entireProcessTree: true) becomes a single sys-call invocation. It's not just way faster but simply way more reliable than current approach.

An experiment that I've run for #123865 (comment) shows 44x wall clock time improvement and 4879x less allocated memory when dealing only with process tree that contained 3 child processes.

Activity

  1. added this to the 11.0.0 milestone on Mar 29, 2026
  2. self-assigned this
    on Mar 29, 2026
  3. dotnet-policy-service commented on Mar 29, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
    See info in area-owners.md if you want to be subscribed.

  4. adamsitnik commented on Mar 29, 2026

    @adamsitnik
    MemberAuthor
  5. jkotas commented on Mar 29, 2026

    @jkotas
    Member

    we should go one step further and always create a new job when starting new Process with CreateProcess on Windows.

    This would be an observable behavior change. It is not unusual for programs to special case behavior when running inside a job. IsProcessInJob Windows API encourages that. I think this should be an opt-in behavior.

    Process.Kill(entireProcessTree: true) becomes a single sys-call invocation. It's not just way faster but simply way more reliable than current approach.

    The job tree is not the same as the process tree. Again, observable behavior change.

  6. adamsitnik commented on Jun 29, 2026

    @adamsitnik
    MemberAuthor

    Closing as not planned for the reasons described by @jkotas

  7. removed this from the 11.0.0 milestone on Jun 29, 2026
  8. locked and limited conversation to collaborators on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions