dccmmtop / notebook

个人博客记录
0 stars 0 forks source link

获取正在运行的进程 #102

Open dccmmtop opened 2 years ago

dccmmtop commented 2 years ago

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

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
}