diff --git a/.travis.yml b/.travis.yml index 8f794f7..937c712 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: go go: - - 1.2.1 + - 1.11.x + - 1.12.x + - 1.13.x diff --git a/process_android.go b/process_android.go new file mode 100644 index 0000000..7e75036 --- /dev/null +++ b/process_android.go @@ -0,0 +1,47 @@ +// +build android + +package ps + +import ( + "fmt" + "io/ioutil" + "strings" +) + +// Refresh reloads all the data associated with this process. +func (p *UnixProcess) Refresh() error { + statPath := fmt.Sprintf("/proc/%d/stat", p.pid) + dataBytes, err := ioutil.ReadFile(statPath) + if err != nil { + return err + } + cmdPath := fmt.Sprintf("/proc/%d/cmdline", p.pid) + cmdBytes, err := ioutil.ReadFile(cmdPath) + if err != nil { + return err + } + + // First, parse out the image name + cmd := string(cmdBytes) + args := strings.SplitN(cmd, string(0x0), 2) + if len(args) > 0 { + p.binary = args[0] + } + data := string(dataBytes) + binStart := strings.IndexRune(data, '(') + 1 + binEnd := strings.IndexRune(data[binStart:], ')') + if p.binary == "" { + p.binary = data[binStart : binStart+binEnd] + } + + // Move past the image name and start parsing the rest + data = data[binStart+binEnd+2:] + _, err = fmt.Sscanf(data, + "%c %d %d %d", + &p.state, + &p.ppid, + &p.pgrp, + &p.sid) + + return err +} diff --git a/process_linux.go b/process_linux.go index c1558f7..af6c37c 100644 --- a/process_linux.go +++ b/process_linux.go @@ -1,4 +1,4 @@ -// +build linux +// +build linux,!android package ps