mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-02 22:17:08 +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) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out := []*Process{}
|
|
||||||
|
|
||||||
for _, proc := range procs {
|
out := []*Process{}
|
||||||
parent, err := proc.Parent()
|
for _, proc := range dst {
|
||||||
|
p, err := NewProcess(int32(proc.ProcessID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
out = append(out, p)
|
||||||
if parent.Pid == p.Pid {
|
|
||||||
out = append(out, proc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user