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
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
//go:build windows
|
|
|
|
package proc
|
|
|
|
import (
|
|
"github.com/pranshuparmar/witr/pkg/model"
|
|
)
|
|
|
|
// ListProcesses returns all running processes with the columns the TUI renders:
|
|
// PID/PPID/command name, owner, start time, command line, CPU% and resident
|
|
// memory. Each process is opened to read its metrics; fields that can't be read
|
|
// (protected/system processes without elevation) are left empty rather than
|
|
// failing the whole list. The TUI loads this asynchronously.
|
|
//
|
|
// The command line is read via NtQueryInformationProcess (windowsProcessCmdline)
|
|
// rather than a PEB walk, so it performs no remote process-memory access and is
|
|
// safe to call across every process.
|
|
func ListProcesses() ([]model.Process, error) {
|
|
procs, err := enumerateProcesses()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out := make([]model.Process, 0, len(procs))
|
|
for _, p := range procs {
|
|
rss, cpu, cpuTime, started := windowsProcMetrics(p.PID)
|
|
out = append(out, model.Process{
|
|
PID: p.PID,
|
|
PPID: p.PPID,
|
|
Command: p.Exe,
|
|
Cmdline: windowsProcessCmdline(p.PID),
|
|
User: readUser(p.PID),
|
|
StartedAt: started,
|
|
CPUPercent: cpu,
|
|
MemoryRSS: rss,
|
|
MemoryPercent: windowsMemoryPercent(rss),
|
|
Health: windowsHealth(rss, cpuTime),
|
|
})
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// ListProcessSnapshot collects a lightweight view of running processes for
|
|
// child/descendant discovery. Backed by ToolHelp32 (no PowerShell, no WMI) so
|
|
// it never blocks on a stalled CIM provider.
|
|
func ListProcessSnapshot() ([]model.Process, error) {
|
|
procs, err := enumerateProcesses()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]model.Process, 0, len(procs))
|
|
for _, p := range procs {
|
|
out = append(out, model.Process{
|
|
PID: p.PID,
|
|
PPID: p.PPID,
|
|
Command: p.Exe,
|
|
})
|
|
}
|
|
return out, nil
|
|
}
|