1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

implements process.exe on linux.

This commit is contained in:
Shirou WAKAYAMA 2014-04-25 15:22:18 +09:00
parent 51c2995c2b
commit a6e7b8261d
2 changed files with 14 additions and 2 deletions

View File

@ -80,7 +80,7 @@ Current Status
- create_time (linux)
- status (linux)
- cwd (linux)
- exe (freebsd)
- exe (linux, freebsd)
- uids (linux)
- gids (linux)
- terminal (linux)

View File

@ -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")