From 4f7834af2567bd02a5f68e032b7f5630f2b7538f Mon Sep 17 00:00:00 2001 From: Nex Date: Fri, 21 Oct 2016 12:07:28 +0200 Subject: [PATCH] Added attempt to get exe path from pid --- process/process_darwin.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/process/process_darwin.go b/process/process_darwin.go index 8ba1619..1b336ad 100644 --- a/process/process_darwin.go +++ b/process/process_darwin.go @@ -80,7 +80,22 @@ func (p *Process) Name() (string, error) { return common.IntToString(k.Proc.P_comm[:]), nil } func (p *Process) Exe() (string, error) { - return "", common.ErrNotImplementedError + bin, err := exec.LookPath("lsof") + if err != nil { + return "", err + } + + var cmd []string + cmd := []string{"-p", p.Pid, "-Fn", "|", "awk", "'NR==3{print}'", "|", "sed", "'s/n\\//\\//'"} + + out, err = invoke.Command(bin, cmd...) + if err != nil { + return "", err + } + + ret = strings.TrimSpace(out) + + return ret, nil } // Cmdline returns the command line arguments of the process as a string with