Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: go

go:
- 1.2.1
- 1.11.x
- 1.12.x
- 1.13.x
47 changes: 47 additions & 0 deletions process_android.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion process_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux
// +build linux,!android

package ps

Expand Down