diff --git a/process_netbsd.go b/process_netbsd.go new file mode 100644 index 0000000..166e7e5 --- /dev/null +++ b/process_netbsd.go @@ -0,0 +1,35 @@ +// +build netbsd + +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 + } + + // First, parse out the image name + data := string(dataBytes) + binStart := strings.IndexRune(data, '(') + 1 + binEnd := strings.IndexRune(data[binStart:], ')') + 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_unix.go b/process_unix.go index cd217a8..e2612c3 100644 --- a/process_unix.go +++ b/process_unix.go @@ -1,4 +1,4 @@ -// +build linux solaris +// +build linux netbsd solaris package ps diff --git a/process_unix_test.go b/process_unix_test.go index 754073e..a4b0d21 100644 --- a/process_unix_test.go +++ b/process_unix_test.go @@ -1,4 +1,4 @@ -// +build linux solaris +// +build linux netbsd solaris package ps