Skip to content

Commit af7fda5

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 183f7c8 commit af7fda5

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
@@ -390,6 +390,7 @@ impl Command {
390390
Process {
391391
handle: Handle::from_raw_handle(pi.hProcess),
392392
main_thread_handle: Handle::from_raw_handle(pi.hThread),
393+
id: pi.dwProcessId,
393394
},
394395
pipes,
395396
))
@@ -652,6 +653,7 @@ impl From<io::Stderr> for Stdio {
652653
pub struct Process {
653654
handle: Handle,
654655
main_thread_handle: Handle,
656+
id: u32,
655657
}
656658

657659
impl Process {
@@ -670,7 +672,7 @@ impl Process {
670672
}
671673

672674
pub fn id(&self) -> u32 {
673-
unsafe { c::GetProcessId(self.handle.as_raw_handle()) }
675+
self.id
674676
}
675677

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

0 commit comments

Comments
 (0)