Remove unused process tree function GetChildren()

This commit is contained in:
Bryan Boreham
2018-02-26 08:54:31 +00:00
parent 44076048ca
commit c06429b92a
2 changed files with 0 additions and 32 deletions

View File

@@ -23,10 +23,6 @@ func (m *mockProcessTree) GetParent(pid int) (int, error) {
return parent, nil
}
func (m *mockProcessTree) GetChildren(int) ([]int, error) {
panic("Not implemented")
}
func TestTagger(t *testing.T) {
mtime.NowForce(time.Now())
defer mtime.NowReset()

View File

@@ -7,7 +7,6 @@ import (
// Tree represents all processes on the machine.
type Tree interface {
GetParent(pid int) (int, error)
GetChildren(pid int) ([]int, error)
}
type tree struct {
@@ -33,30 +32,3 @@ func (pt *tree) GetParent(pid int) (int, error) {
return proc.PPID, nil
}
// GetChildren
func (pt *tree) GetChildren(pid int) ([]int, error) {
_, ok := pt.processes[pid]
if !ok {
return []int{}, fmt.Errorf("PID %d not found", pid)
}
var isChild func(id int) bool
isChild = func(id int) bool {
p, ok := pt.processes[id]
if !ok || p.PPID == 0 {
return false
} else if p.PPID == pid {
return true
}
return isChild(p.PPID)
}
children := []int{pid}
for id := range pt.processes {
if isChild(id) {
children = append(children, id)
}
}
return children, nil
}