Skip to content

Commit

Permalink
Breaking change: use state code rather than "description"
Browse files Browse the repository at this point in the history
For process.Status(), linux is the only platform where it's possible to
get state descriptions. This is specific to the linux /proc/<pid>/status
file.

I think it would be better to get the more platform-neutral state codes,
which are also present on FreeBSD, OpenBSD, darwin, etc.

The state codes are also better documented on "man proc" and "man ps"
  • Loading branch information
sparrc committed Mar 8, 2016
1 parent 715c421 commit f1d69a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,7 @@ func (p *Process) fillFromStatus() error {
case "Name":
p.name = strings.Trim(value, " \t")
case "State":
// get between "(" and ")"
s := strings.Index(value, "(") + 1
e := strings.Index(value, ")")
p.status = value[s:e]
p.status = value[0:1]
case "Uid":
p.uids = make([]int32, 0, 4)
for _, i := range strings.Split(value, "\t") {
Expand Down
2 changes: 1 addition & 1 deletion process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func Test_Process_Status(t *testing.T) {
if err != nil {
t.Errorf("geting status error %v", err)
}
if !strings.HasPrefix(v, "S") && v != "running" && v != "sleeping" {
if v != "R" && v != "S" {
t.Errorf("could not get state %v", v)
}
}
Expand Down

0 comments on commit f1d69a0

Please sign in to comment.