implement cwd on linux.

pull/4/head
Shirou WAKAYAMA 11 years ago
parent 2e50131db8
commit 51c2995c2b

@ -79,6 +79,7 @@ Current Status
- cmdline (linux) - cmdline (linux)
- create_time (linux) - create_time (linux)
- status (linux) - status (linux)
- cwd (linux)
- exe (freebsd) - exe (freebsd)
- uids (linux) - uids (linux)
- gids (linux) - gids (linux)
@ -99,7 +100,6 @@ Current Status
- Process class - Process class
- parent - parent
- cwd
- username - username
- ionice - ionice
- rlimit - rlimit

@ -37,7 +37,7 @@ func NewProcess(pid int32) (*Process, error) {
// Fill Process information from fillFuncs // Fill Process information from fillFuncs
var wg sync.WaitGroup var wg sync.WaitGroup
funcs := []fillFunc{fillFromStat, fillFromStatus, fillFromfd, funcs := []fillFunc{fillFromStat, fillFromStatus, fillFromfd,
fillFromCmdline, fillFromStatm} fillFromCmdline, fillFromStatm, fillFromCwd}
wg.Add(len(funcs)) wg.Add(len(funcs))
for _, f := range funcs { for _, f := range funcs {
@ -77,6 +77,18 @@ func fillFromfd(pid int32, p *Process) error {
return nil return nil
} }
// Get cwd from /proc/(pid)/cwd
func fillFromCwd(pid int32, p *Process) error {
cwdPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "cwd")
cwd, err := os.Readlink(cwdPath)
if err != nil {
return err
}
p.Cwd = string(cwd)
return nil
}
// Get cmdline from /proc/(pid)/cmdline // Get cmdline from /proc/(pid)/cmdline
func fillFromCmdline(pid int32, p *Process) error { func fillFromCmdline(pid int32, p *Process) error {
cmdPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "cmdline") cmdPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "cmdline")

Loading…
Cancel
Save