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:
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…
x
Reference in New Issue
Block a user