Skip to content

Commit 738e445

Browse files
committed
Remove GetProcessId usage
Instead, store the ID when spawning the process. >= XP SP1 / Vista / Server 2003 https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getprocessid
1 parent 40fb14d commit 738e445

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

library/std/src/sys/pal/windows/process.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ impl Command {
394394
Process {
395395
handle: Handle::from_raw_handle(pi.hProcess),
396396
main_thread_handle: Handle::from_raw_handle(pi.hThread),
397+
id: pi.dwProcessId,
397398
},
398399
pipes,
399400
))
@@ -657,6 +658,7 @@ impl From<io::Stderr> for Stdio {
657658
pub struct Process {
658659
handle: Handle,
659660
main_thread_handle: Handle,
661+
id: u32,
660662
}
661663

662664
impl Process {
@@ -675,7 +677,7 @@ impl Process {
675677
}
676678

677679
pub fn id(&self) -> u32 {
678-
unsafe { c::GetProcessId(self.handle.as_raw_handle()) }
680+
self.id
679681
}
680682

681683
pub fn main_thread_handle(&self) -> BorrowedHandle<'_> {

0 commit comments

Comments
 (0)