Improve performance of finding child processes on Windows

pull/436/head
John Liu 8 years ago committed by GitHub
parent a6cc94f428
commit d28c254aaf

@ -301,22 +301,22 @@ func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
}
func (p *Process) Children() ([]*Process, error) {
procs, err := processes()
var dst []Win32_Process
query := wmi.CreateQuery(&dst, fmt.Sprintf("Where ParentProcessId = %d", p.Pid))
err := wmi.Query(query, &dst)
if err != nil {
return nil, err
}
out := []*Process{}
for _, proc := range procs {
parent, err := proc.Parent()
out := []*Process{}
for _, proc := range dst {
p, err := NewProcess(int32(proc.ProcessID))
if err != nil {
continue
}
if parent.Pid == p.Pid {
out = append(out, proc)
}
out = append(out, p)
}
return out, nil
}

Loading…
Cancel
Save