Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Add netbsd support via mount_procfs(8) #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
35 changes: 35 additions & 0 deletions process_netbsd.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion process_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux solaris
// +build linux netbsd solaris

package ps

Expand Down
2 changes: 1 addition & 1 deletion process_unix_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux solaris
// +build linux netbsd solaris

package ps

Expand Down