Merge pull request #453 from Lomanic/windows-enumprocesses

Use w32.EnumProcesses to get pids on Windows in process.Pids()
pull/458/head
shirou 8 years ago committed by GitHub
commit 699bd0f65a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -93,17 +93,18 @@ func init() {
} }
func Pids() ([]int32, error) { func Pids() ([]int32, error) {
// inspired by https://gist.github.com/henkman/3083408
var ret []int32 var ret []int32
ps := make([]uint32, 2048)
var read uint32 = 0
procs, err := Processes() if !w32.EnumProcesses(ps, uint32(len(ps)), &read) {
if err != nil { return nil, fmt.Errorf("could not get w32.EnumProcesses")
return ret, nil
} }
for _, proc := range procs { for _, pid := range ps[:read/4] {
ret = append(ret, proc.Pid) ret = append(ret, int32(pid))
} }
return ret, nil return ret, nil
} }

Loading…
Cancel
Save