You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
992 B
Go
50 lines
992 B
Go
// +build windows
|
|
|
|
package staros
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"b612.me/wincmd"
|
|
)
|
|
|
|
// FindProcessByName 通过进程名来查询应用信息
|
|
func FindProcessByName(pname string) (data []Process, err error) {
|
|
var lists []map[string]string
|
|
lists, err = wincmd.GetRunningProcess()
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range lists {
|
|
if v["name"] == pname {
|
|
var tmp Process
|
|
tmp.Name = pname
|
|
tmp.Pid, _ = strconv.ParseInt(v["pid"], 10, 64)
|
|
tmp.PPid, _ = strconv.ParseInt(v["ppid"], 10, 64)
|
|
data = append(data, tmp)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// FindProcessByPid 通过pid来查询应用信息
|
|
func FindProcessByPid(pid int64) (data Process, err error) {
|
|
var lists []map[string]string
|
|
lists, err = wincmd.GetRunningProcess()
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range lists {
|
|
if v["pid"] == fmt.Sprint(pid) {
|
|
data.Name = v["name"]
|
|
data.Pid = pid
|
|
data.PPid, _ = strconv.ParseInt(v["ppid"], 10, 64)
|
|
return
|
|
}
|
|
}
|
|
err = errors.New("Not Found")
|
|
return
|
|
}
|