From 7822afd3917edfd62f05d62dd460415c215e5bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E6=A5=BD=E5=9D=82=E5=96=B5=E5=96=B5?= Date: Thu, 25 Jul 2024 19:50:39 +0800 Subject: [PATCH] feat(server): kill -9 is not recommand, syscall.Kill SIGTERM instead of. (#107) GREAT Thx for the PR --- server/internal/worker.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/internal/worker.go b/server/internal/worker.go index e3daf80a..788649f1 100644 --- a/server/internal/worker.go +++ b/server/internal/worker.go @@ -6,6 +6,7 @@ import ( "os/exec" "strconv" "strings" + "syscall" "time" "github.com/gogf/gf/container/gmap" @@ -71,10 +72,9 @@ func (w *Worker) start(req *StartReq) (err error) { func (w *Worker) stop(requestId string, channelName string) (err error) { slog.Info("Worker stop start", "channelName", channelName, "requestId", requestId, logTag) - shell := fmt.Sprintf("kill -9 %d", w.Pid) - output, err := exec.Command("sh", "-c", shell).CombinedOutput() + err = syscall.Kill(w.Pid, syscall.SIGTERM) if err != nil { - slog.Error("Worker kill failed", "err", err, "output", output, "channelName", channelName, "worker", w, "requestId", requestId, logTag) + slog.Error("Worker kill failed", "err", err, "channelName", channelName, "worker", w, "requestId", requestId, logTag) return }