获取正在运行的进程

获取系统中正在运行的进程。和平台无关

import (
 ps "github.com/mitchellh/go-ps"
)

func running() bool {
  processList, err := ps.Processes()
  if err != nil {
    fmt.Printf("err %v\n",err);
    return false
  }

  var process ps.Process
  num := 0
  for x := range processList {
    process = processList[x]
    if process.Executable() == "test.exe" {
      num ++
      if num >= 2 {
      fmt.Println("on running")
      return true
      }
    }
  }
  return false
}