提交 4b14852d 编写于 作者: Z zhaoke

Add kill linux process by uuid

上级 5574ce45
package execHelper
import (
"fmt"
"os/exec"
"strings"
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
......@@ -93,10 +91,3 @@ func setBuildTool(testSet *serverDomain.TestSet, req serverDomain.WsReq) {
testSet.BuildTool = commConsts.UnitBuildToolMap[strings.TrimSpace(arr[0])]
}
}
func KillLinuxProcessByUUID(uuid string) {
command := fmt.Sprintf(`ps -ef | grep %s | grep -v "grep" | awk '{print $2}' | xargs kill -9`, uuid)
cmd := exec.Command(command)
cmd.Start()
}
......@@ -41,9 +41,8 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
}
ctxt, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(timeout))
defer cancel()
uuidString := ""
uuidString := uuid.Must(uuid.NewV4()).String()
if commonUtils.IsWin() {
uuidString = uuid.Must(uuid.NewV4()).String()
scriptInterpreter := ""
if strings.ToLower(lang) != "bat" {
scriptInterpreter = configHelper.GetFieldVal(conf, stringUtils.UcFirst(lang))
......@@ -100,7 +99,7 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
if command, ok := commConsts.LangMap[lang]["CompiledCommand"]; ok && command != "" {
filePath = fmt.Sprintf("%s %s %s", lang, command, filePath)
}
cmd = exec.CommandContext(ctxt, "/bin/bash", "-c", filePath)
cmd = exec.CommandContext(ctxt, "/bin/bash", "-c", fmt.Sprintf("%s -uuid %s", filePath, uuidString))
}
}
......@@ -142,15 +141,13 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
}
cmd.Start()
if commonUtils.IsWin() {
go func() {
time.AfterFunc(time.Second*time.Duration(timeout), func() {
KillProcessByUUID(uuidString)
stdout.Close()
stderr.Close()
})
}()
}
go func() {
time.AfterFunc(time.Second*time.Duration(timeout), func() {
KillProcessByUUID(uuidString)
stdout.Close()
stderr.Close()
})
}()
isTerminal := false
reader1 := bufio.NewReader(stdout)
stdOutputArr := make([]string, 0)
......
......@@ -10,6 +10,6 @@ import (
func KillProcessByUUID(uuid string) {
command := fmt.Sprintf(`ps -ef | grep %s | grep -v "grep" | awk '{print $2}' | xargs kill -9`, uuid)
cmd := exec.Command(command)
cmd := exec.Command("/bin/bash", "-c", command)
cmd.Start()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册