1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-05-01 13:48:52 +08:00

Improve performance of finding child processes on Windows

This commit is contained in:
John Liu 2017-10-06 12:23:54 -04:00 committed by GitHub
parent a6cc94f428
commit d28c254aaf

View File

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