Use w32.EnumProcesses to get pids on Windows in process.Pids()

This commit is contained in:
Lomanic 2017-11-12 03:08:47 +01:00
parent 982c40e07b
commit 0314bc81f3
1 changed files with 7 additions and 6 deletions

View File

@ -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
}