1
0
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:
Shirou WAKAYAMA 2014-04-23 13:25:00 +09:00
commit 4c6a276474
3 changed files with 54 additions and 9 deletions

View File

@ -66,6 +66,8 @@ Current Status
- disk_usage (linux, freebsd, windows) - disk_usage (linux, freebsd, windows)
- boot_time (linux, freebsd, windows(but little broken)) - boot_time (linux, freebsd, windows(but little broken))
- users (linux, freebsd) - users (linux, freebsd)
- pids (freebsd)
- pid_exists (freebsd)
- not yet - not yet
@ -74,11 +76,14 @@ Current Status
- disk_io_counters - disk_io_counters
- net_io_counters - net_io_counters
- net_connections - net_connections
- pids - Process class
- pid_exists
- future work
- process_iter - process_iter
- wait_procs - wait_procs
- process class
License License
------------ ------------

View File

@ -65,3 +65,32 @@ type Io_countersStat struct {
Read_bytes int32 Read_bytes int32
Write_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
}

View File

@ -1,16 +1,27 @@
package gopsutil package gopsutil
import ( import (
"encoding/json"
"fmt"
"testing" "testing"
) )
func Test(t *testing.T) { func Test_Pids(t *testing.T) {
v, err := findProcess(0) ret, err := Pids()
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
d, _ := json.Marshal(v) if len(ret) == 0 {
fmt.Printf("%s\n", d) 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)
}
} }