Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Adding Kill(bool entireProcessTree) -- terminates a process tree #34147

Merged
merged 64 commits into from
Feb 2, 2019

Conversation

bgribaudo
Copy link
Contributor

[Implements API approved by #26234]

Summary

When Kill(bool entireProcessTree)'s argument is false, behaves identical to Kill(); when true, terminates the current process and all descendant processes (children, grandchildren, etc.).

Platform Implementation Status

Implemented for Windows, OSX and Linux; not implemented for UAP, UnknownUnix or FreeBSD.

Notes

Potential low-hanging fruit: Behind-the-scenes, the logic in this PR enumerates child processes. This functionality could be leveraged to easily implement #25855.

Windows-specific logic inspired by msbuild's NativeMethodsShared KillTree.

[This PR replaces #31827]

@bgribaudo
Copy link
Contributor Author

@dotnet-bot please test Windows x64 Debug Build

@danmoseley
Copy link
Member

@dotnet-bot test NETFX x86 Release Build please (AV in csc .. bit worrying, but no diagnostics)

@danmoseley
Copy link
Member

@wtgodbe do you have any further feedback?

@safern
Copy link
Member

safern commented Jan 29, 2019

This branch still has an old Helix SDK, that is why we're hitting the RestApiException. I'll retry the failing leg.

Copy link
Member

@wtgodbe wtgodbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minus the 2 nitpicks

@danmoseley
Copy link
Member

@tmds any remaining feedback?

@bgribaudo
Copy link
Contributor Author

bgribaudo commented Feb 1, 2019

@dotnet-bot build corefx-ci please

@safern
Copy link
Member

safern commented Feb 2, 2019

Note that to trigger corefx-ci comments are broken. It is a known issue and we're waiting for a fix.

It is probable that the build will fail. It seems like if you want it working, you will need to rebase or merge with master. Since all other builds are green and corefx-ci covers the same builds. We can ignore it in this PR since it is fairly old.

@danmoseley danmoseley merged commit 81bd671 into dotnet:master Feb 2, 2019
@danmoseley
Copy link
Member

This has been open long enough and scrutinized enough 😃

Thanks a lot @bgribaudo for the contribution. As you can see, usually community PR's go through much faster. I guess it was several reasons including the fiddly change. I hope it does not deter you from contributing in future. We have lots of issues labeled up for grabs.

@krwq
Copy link
Member

krwq commented Feb 3, 2019

Thanks @bgribaudo

@bgribaudo
Copy link
Contributor Author

Thank you, @danmosemsft, @krwq, @tmds, @wtgodbe (and anyone else I'm missing that participated)! I appreciate your patience on this one. :-)

@bgribaudo bgribaudo deleted the ProcessKillPR branch February 14, 2019 12:16
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…net/corefx#34147)

* Adding Kill(bool entireProcessTree)

* Slightly cleaning up NtQueryInformationProcess interop code

* Trimming down PROCESSINFOCLASS enum members

* Refactoring--adjusting indents, changing param from ref to out, etc.

* Revising NtQueryInformationProcess-related code

* Comment & indentation tweaks

* TryGetParentProcessId -> GetParentProcessId rename/refactoring -- includes eliminating the output parameter

* Removing UAP double-definition of KillTree()

* Moving code so that not included in Uap build & tests so that not included in Uap and NetFx builds

* Moving relevant code from Windows -> Win32

* Moving relevant code from Windows -> Win32

* Working to satisfy contract for Uap (code written to fail test to verify that it works)

* Typo fix (missing return signature)

* Removing unneeded Uap-specific test file

* Adding temp. test to verify that UAP CI is catching test failures.

* Using lists (vs. enumerables) as test assert arguments

* Giving Kill() a moment to take effect

* Removing whitespace

* Removing irrelevant comment

* Revising initial check that ensures process has started.

* Moving process tree creation outside of finally

* Adding retry logic to tests

* Adjusting retry times/delay

* Adding backoff to retry helper

* Introducing non-auto-dispose variant of CreateProcess; refactoring

* Improving exception handling

* Moving catch

* Minor refactoring/reformatting

* Testing test execution by CI

* Partially removing code testing CI system

* Experimenting with implementing on OSX

* Adding cast

* Re-adding [ActiveIssue] attribute accidentally removed

* Re-adding inadvertently-removed commented-out test attributes

* Allowing aggregated Win32Exceptions to propagate out; disallowing calling Kill(true) on tree containing caller

* Adjusting test attributes, removing CI verification test, adjusting expected exception

* Marking non-local process test as platform-specific

* Adding PlatformNotSupported throw for Uap.

* Adding missing closing XML tag

* XML doc tag tweak

* Cleaning up two merge artifacts (whitespace + comment)

* Adding console output for debugging

* Fixing typo

* Removing logging to console

* Removing unused parameter

* Unix & OSX exception tweaks

* Variable rename

* Whitespace tweak

* Refactoring IsInTreeOf to use @danmosemsft's optimization suggestion; Renaming method

* Missed a rename

* Tweaking

* Reworking IsSelfOrDescendant to use refactored GetChildProcesses

* Minor fix

* Applying minor tweaks suggested by @krwq

* Adding a delay safety cutoff to RetryWithBackoff per
@krwq's suggestion.

* Adjusting backoff delay max to 10 seconds.

* IsSelfOrDescendant -> IsSelfOrDescendantOf

* Unix: If Stop() fails, don't try to continue with the process (thanks @tmds!).

* Fixing typo.

* Adding comments about kill/stop returning before termination/stopping completes.

* Adding comment.


Commit migrated from dotnet/corefx@81bd671
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.