diff --git a/process/process_test.go b/process/process_test.go index 786eb51..40e3639 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -294,7 +294,7 @@ func Test_Process_Name(t *testing.T) { t.Errorf("getting name error %v", err) } if !strings.Contains(n, "process.test") { - t.Errorf("invalid Exe %s", n) + t.Errorf("invalid Name %s", n) } } diff --git a/process/process_windows.go b/process/process_windows.go index 0a5b00f..14ed030 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "os" + "path/filepath" "reflect" "strings" "syscall" @@ -319,18 +320,19 @@ func (p *Process) PpidWithContext(ctx context.Context) (int32, error) { } func (p *Process) NameWithContext(ctx context.Context) (string, error) { - ppid, _, name, err := getFromSnapProcess(p.Pid) + if p.Pid == 0 { + return "System Idle Process", nil + } + if p.Pid == 4 { + return "System", nil + } + + exe, err := p.ExeWithContext(ctx) if err != nil { return "", fmt.Errorf("could not get Name: %s", err) } - // if no errors and not cached already, cache ppid - p.parent = ppid - if 0 == p.getPpid() { - p.setPpid(ppid) - } - - return name, nil + return filepath.Base(exe), nil } func (p *Process) TgidWithContext(ctx context.Context) (int32, error) {