implement freebsd libproc query, BUT it's reading wrong values
This commit is contained in:
parent
c908ee8b6e
commit
edff33b0b3
2 changed files with 41 additions and 4 deletions
37
proc_freebsd.go
Normal file
37
proc_freebsd.go
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
//go:build freebsd
|
||||||
|
|
||||||
|
package proc
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lproc
|
||||||
|
#include <libproc.h>
|
||||||
|
|
||||||
|
static int libproc_state(int pid) {
|
||||||
|
int ret;
|
||||||
|
struct proc_handle* proc;
|
||||||
|
|
||||||
|
ret = proc_attach((pid_t)pid, PATTACH_RDONLY | PATTACH_NOSTOP, &proc);
|
||||||
|
if (ret) return -ret;
|
||||||
|
|
||||||
|
ret = proc_state(proc);
|
||||||
|
proc_detach(proc, 0);
|
||||||
|
proc_free(proc);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func queryInternal(pid int) (ProcState, error) {
|
||||||
|
var ret C.int
|
||||||
|
ret = C.libproc_state((C.int)(pid))
|
||||||
|
if ret < 0 {
|
||||||
|
return 0, errors.New(fmt.Sprintf("libproc: %d", (int)(-ret)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ProcState)(ret), nil
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
//go:build linux
|
|
||||||
|
|
||||||
package proc
|
package proc
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestQuery(t *testing.T) {
|
func TestQuery(t *testing.T) {
|
||||||
if _, err := Query(1); err != nil {
|
if _, err := Query(1); err != nil {
|
||||||
t.Failed()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue