This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Commit 1d83d60
Speed up Windows ProcessManager.OpenProcess (#25478)
If a process is running as a normal user (not elevated), many calls to
`kernel32.OpenProcess` fail.
In `ProcessManager.OpenProcess`, when the first call to `kernel32.OpenProcess`
fails, another call is made indirectly in `ProcessManager.IsProcessRunning`
which will also fail.
When `ProcessManager.IsProcessRunning` can't get a handle to the process, it
falls back on a much more expensive check - enumerating all processes.
The fix is to assume the process is running if the error code is
ERROR_ACCESS_DENIED.
This performance issue adds roughly 1 second of overhead when running
`Get-Process` in an interactive non-elevated PowerShell session where
the CPU property is displayed.1 parent d61b609 commit 1d83d60
File tree
1 file changed
+2
-1
lines changed- src/System.Diagnostics.Process/src/System/Diagnostics
1 file changed
+2
-1
lines changedLines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
| 199 | + | |
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
| |||
0 commit comments