From 1ecf1a011b838d6e27372058e946fa129ddd131c Mon Sep 17 00:00:00 2001 From: Shirou WAKAYAMA Date: Thu, 24 Apr 2014 18:28:45 +0900 Subject: [PATCH] posix function move to process_posix.go --- process.go | 44 -------------------------------------------- process_posix.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 process_posix.go diff --git a/process.go b/process.go index ff9110c..a5ddae4 100644 --- a/process.go +++ b/process.go @@ -1,11 +1,5 @@ package gopsutil -import ( - "os" - "strings" - "syscall" -) - type Process struct { Pid int32 `json:"pid"` Ppid int32 `json:"ppid"` @@ -86,41 +80,3 @@ func Pid_exists(pid int32) (bool, error) { return false, err } - -// POSIX -func getTerminalMap() (map[uint64]string, error) { - ret := make(map[uint64]string) - termfiles := make([]string, 0) - - d, err := os.Open("/dev") - if err != nil { - return nil, err - } - defer d.Close() - - devnames, err := d.Readdirnames(-1) - for _, devname := range devnames { - if strings.HasPrefix(devname, "/dev/tty") { - termfiles = append(termfiles, "/dev/tty/"+devname) - } - } - - ptsd, err := os.Open("/dev/pts") - if err != nil { - return nil, err - } - defer ptsd.Close() - - ptsnames, err := ptsd.Readdirnames(-1) - for _, ptsname := range ptsnames { - termfiles = append(termfiles, "/dev/pts/"+ptsname) - } - - for _, name := range termfiles { - stat := syscall.Stat_t{} - syscall.Stat(name, &stat) - rdev := stat.Rdev - ret[rdev] = strings.Replace(name, "/dev", "", -1) - } - return ret, nil -} diff --git a/process_posix.go b/process_posix.go new file mode 100644 index 0000000..e1f85c0 --- /dev/null +++ b/process_posix.go @@ -0,0 +1,47 @@ +// +build linux freebsd + +package gopsutil + +import ( + "os" + "strings" + "syscall" +) + +// POSIX +func getTerminalMap() (map[uint64]string, error) { + ret := make(map[uint64]string) + termfiles := make([]string, 0) + + d, err := os.Open("/dev") + if err != nil { + return nil, err + } + defer d.Close() + + devnames, err := d.Readdirnames(-1) + for _, devname := range devnames { + if strings.HasPrefix(devname, "/dev/tty") { + termfiles = append(termfiles, "/dev/tty/"+devname) + } + } + + ptsd, err := os.Open("/dev/pts") + if err != nil { + return nil, err + } + defer ptsd.Close() + + ptsnames, err := ptsd.Readdirnames(-1) + for _, ptsname := range ptsnames { + termfiles = append(termfiles, "/dev/pts/"+ptsname) + } + + for _, name := range termfiles { + stat := syscall.Stat_t{} + syscall.Stat(name, &stat) + rdev := stat.Rdev + ret[rdev] = strings.Replace(name, "/dev", "", -1) + } + return ret, nil +}