This commit is contained in:
cdle
2021-09-17 07:04:13 +08:00
parent 0986d5baf0
commit d7be38dcf4
2 changed files with 37 additions and 0 deletions
+6
View File
@@ -22,6 +22,12 @@ var ExecPath, _ = filepath.Abs(filepath.Dir(os.Args[0]))
var Config Yaml
func init() {
killp()
for _, arg := range os.Args {
if arg == "-d" {
Daemon()
}
}
ReadYaml(ExecPath+"/conf/", &Config, "https://raw.githubusercontent.com/cdle/sillyGirl/main/conf/demo_config.yaml")
InitReplies()
initToHandleMessage()
+31
View File
@@ -2,8 +2,10 @@ package core
import (
"errors"
"fmt"
"os"
"os/exec"
"regexp"
"runtime"
"strings"
@@ -55,3 +57,32 @@ func CompileCode() error {
}
return nil
}
func killp() {
pids, err := ppid()
if err == nil {
if len(pids) == 0 {
return
} else {
exec.Command("sh", "-c", "kill -9 "+strings.Join(pids, " ")).Output()
}
} else {
return
}
}
func ppid() ([]string, error) {
pid := fmt.Sprint(os.Getpid())
pids := []string{}
rtn, err := exec.Command("sh", "-c", "pidof "+pname).Output()
if err != nil {
return pids, err
}
re := regexp.MustCompile(`[\d]+`)
for _, v := range re.FindAll(rtn, -1) {
if string(v) != pid {
pids = append(pids, string(v))
}
}
return pids, nil
}