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:
parent
51c2995c2b
commit
a6e7b8261d
@ -80,7 +80,7 @@ Current Status
|
||||
- create_time (linux)
|
||||
- status (linux)
|
||||
- cwd (linux)
|
||||
- exe (freebsd)
|
||||
- exe (linux, freebsd)
|
||||
- uids (linux)
|
||||
- gids (linux)
|
||||
- terminal (linux)
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user