项目文件夹

文件
wehub-resource-sync 36b3af2e3d
PR Check / Code Quality: Format (push) Failing after 1s
PR Check / Code Quality: Lint (darwin) (push) Failing after 0s
PR Check / Code Quality: Lint (freebsd) (push) Failing after 1s
PR Check / Code Quality: Lint (windows) (push) Failing after 1s
PR Check / Code Quality: Lint (linux) (push) Failing after 1s
PR Check / Security: Vulnerability Scan (push) Failing after 0s
Update Documentation / update-docs (push) Failing after 2s
PR Check / Code Quality: Vendor (push) Failing after 1s
PR Check / Code Quality: Coverage (push) Failing after 0s
PR Check / Tests: Unit (macos-latest) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04-arm) (push) Has been cancelled
PR Check / Tests: Unit (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:06 +08:00

45 行
701 B
Go

package proc
import (
"fmt"
"github.com/pranshuparmar/witr/pkg/model"
)
func ResolveAncestry(pid int) ([]model.Process, error) {
var chain []model.Process
seen := make(map[int]bool)
current := pid
for current > 0 {
if seen[current] {
break // loop protection
}
seen[current] = true
p, err := ReadProcess(current)
if err != nil {
break
}
chain = append(chain, p)
if p.PPID == 0 || p.PID == 1 {
break
}
current = p.PPID
}
if len(chain) == 0 {
return nil, fmt.Errorf("no process ancestry found")
}
// Reverse the chain to get root
for i, j := 0, len(chain)-1; i < j; i, j = i+1, j-1 {
chain[i], chain[j] = chain[j], chain[i]
}
return chain, nil
}