From a6e7b8261d8c6ca88a50835cf1c698be8f69b230 Mon Sep 17 00:00:00 2001 From: Shirou WAKAYAMA Date: Fri, 25 Apr 2014 15:22:18 +0900 Subject: [PATCH] implements process.exe on linux. --- README.rst | 2 +- process_linux.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 2a704724..0e925b2b 100644 --- a/README.rst +++ b/README.rst @@ -80,7 +80,7 @@ Current Status - create_time (linux) - status (linux) - cwd (linux) - - exe (freebsd) + - exe (linux, freebsd) - uids (linux) - gids (linux) - terminal (linux) diff --git a/process_linux.go b/process_linux.go index a8e0746d..70c08633 100644 --- a/process_linux.go +++ b/process_linux.go @@ -37,7 +37,7 @@ func NewProcess(pid int32) (*Process, error) { // Fill Process information from fillFuncs var wg sync.WaitGroup funcs := []fillFunc{fillFromStat, fillFromStatus, fillFromfd, - fillFromCmdline, fillFromStatm, fillFromCwd} + fillFromCmdline, fillFromStatm, fillFromCwd, fillFromExe} wg.Add(len(funcs)) for _, f := range funcs { @@ -89,6 +89,18 @@ func fillFromCwd(pid int32, p *Process) error { return nil } +// Get exe from /proc/(pid)/exe +func fillFromExe(pid int32, p *Process) error { + exePath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "exe") + exe, err := os.Readlink(exePath) + if err != nil { + return err + } + p.Exe = string(exe) + + return nil +} + // Get cmdline from /proc/(pid)/cmdline func fillFromCmdline(pid int32, p *Process) error { cmdPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "cmdline")