-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameProcess.go
More file actions
53 lines (47 loc) · 1.05 KB
/
Copy pathgameProcess.go
File metadata and controls
53 lines (47 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
)
func isLinuxProcessRunning(processName string) bool {
cmd := exec.Command("ps", "-C", processName)
output, err := cmd.Output()
if err != nil {
fmt.Println("Error while checking process status")
return false
}
if len(output) > 0 {
return true
}
return false
}
func isProcessExist(appName string) (bool, string, int) {
appary := make(map[string]int)
cmd := exec.Command("cmd", "/C", "tasklist")
output, _ := cmd.Output() //fmt.Printf("fields: %v\n", output)
n := strings.Index(string(output), "System")
if n == -1 {
fmt.Println("no System process find")
os.Exit(1)
}
data := string(output)[n:]
fields := strings.Fields(data)
for k, v := range fields {
if v == appName {
appary[appName], _ = strconv.Atoi(fields[k+1])
return true, appName, appary[appName]
}
}
return false, appName, -1
}
func killProcessByName(procname string) int {
kill := exec.Command("taskkill", "/IM", procname, "/T", "/F")
err := kill.Run()
if err != nil {
return -1
}
return 0
}