From e9a459828c7702ff5075f70f4dd5cf769fdc208c Mon Sep 17 00:00:00 2001 From: Pierre-Alain TORET Date: Fri, 5 Jan 2018 14:57:17 +0100 Subject: [PATCH] Add DragonFlyBSD support Signed-off-by: Pierre-Alain TORET --- process_dragonfly.go | 29 +++++++++++++++++++++++++++++ process_unix.go | 2 +- process_unix_test.go | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 process_dragonfly.go diff --git a/process_dragonfly.go b/process_dragonfly.go new file mode 100644 index 0000000..bac8f57 --- /dev/null +++ b/process_dragonfly.go @@ -0,0 +1,29 @@ +// +build dragonfly + +package ps + +import ( + "fmt" + "io/ioutil" +) + +// Refresh reloads all the data associated with this process. +func (p *UnixProcess) Refresh() error { + statPath := fmt.Sprintf("/proc/%d/status", p.pid) + dataBytes, err := ioutil.ReadFile(statPath) + if err != nil { + return err + } + + data := string(dataBytes) + + _, err = fmt.Sscanf(data, + "%s %d %d %d %d", + &p.binary, + &p.pid, + &p.ppid, + &p.pgrp, + &p.sid) + + return err +} diff --git a/process_unix.go b/process_unix.go index 3b733ce..598fdc2 100644 --- a/process_unix.go +++ b/process_unix.go @@ -1,4 +1,4 @@ -// +build linux solaris +// +build linux solaris dragonfly package ps diff --git a/process_unix_test.go b/process_unix_test.go index 754073e..11e3233 100644 --- a/process_unix_test.go +++ b/process_unix_test.go @@ -1,4 +1,4 @@ -// +build linux solaris +// +build linux solaris dragonfly package ps