From 0314bc81f32c2594ac7110f4c7be348c04bed290 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Sun, 12 Nov 2017 03:08:47 +0100 Subject: [PATCH] Use w32.EnumProcesses to get pids on Windows in process.Pids() --- process/process_windows.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/process/process_windows.go b/process/process_windows.go index 02478a3..320833b 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -93,17 +93,18 @@ func init() { } func Pids() ([]int32, error) { + // inspired by https://gist.github.com/henkman/3083408 var ret []int32 + ps := make([]uint32, 2048) + var read uint32 = 0 - procs, err := Processes() - if err != nil { - return ret, nil + if !w32.EnumProcesses(ps, uint32(len(ps)), &read) { + return nil, fmt.Errorf("could not get w32.EnumProcesses") } - for _, proc := range procs { - ret = append(ret, proc.Pid) + for _, pid := range ps[:read/4] { + ret = append(ret, int32(pid)) } - return ret, nil }