mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-02 22:17:08 +08:00
Merge branch 'master' of github.com:shirou/gopsutil
This commit is contained in:
commit
4c6a276474
11
README.rst
11
README.rst
@ -66,6 +66,8 @@ Current Status
|
||||
- disk_usage (linux, freebsd, windows)
|
||||
- boot_time (linux, freebsd, windows(but little broken))
|
||||
- users (linux, freebsd)
|
||||
- pids (freebsd)
|
||||
- pid_exists (freebsd)
|
||||
|
||||
- not yet
|
||||
|
||||
@ -74,11 +76,14 @@ Current Status
|
||||
- disk_io_counters
|
||||
- net_io_counters
|
||||
- net_connections
|
||||
- pids
|
||||
- pid_exists
|
||||
- Process class
|
||||
|
||||
- future work
|
||||
|
||||
- process_iter
|
||||
- wait_procs
|
||||
- process class
|
||||
|
||||
|
||||
|
||||
License
|
||||
------------
|
||||
|
29
process.go
29
process.go
@ -65,3 +65,32 @@ type Io_countersStat struct {
|
||||
Read_bytes int32
|
||||
Write_bytes int32
|
||||
}
|
||||
|
||||
func Pids() ([]int32, error) {
|
||||
ret := make([]int32, 0)
|
||||
procs, err := processes()
|
||||
if err != nil {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
for _, p := range procs {
|
||||
ret = append(ret, p.Pid)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func Pid_exists(pid int32) (bool, error) {
|
||||
pids, err := Pids()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, i := range pids {
|
||||
if i == pid {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
|
@ -1,16 +1,27 @@
|
||||
package gopsutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
v, err := findProcess(0)
|
||||
func Test_Pids(t *testing.T) {
|
||||
ret, err := Pids()
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
d, _ := json.Marshal(v)
|
||||
fmt.Printf("%s\n", d)
|
||||
if len(ret) == 0 {
|
||||
t.Errorf("could not get pids %v", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Pid_exists(t *testing.T) {
|
||||
ret, err := Pid_exists(1)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
|
||||
if ret == false {
|
||||
t.Errorf("could not get init process %v", ret)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user