From f72b2b0683417714de2894f3bf1fca42e48628a9 Mon Sep 17 00:00:00 2001 From: "tiny.x" <185120555@qq.com> Date: Mon, 16 Nov 2020 15:08:17 +0800 Subject: [PATCH] fixbug: Under some systems, processes cannot exit using kill -HUP Signed-off-by: tiny.x <185120555@qq.com> --- exec/bin/burncpu/burncpu.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/exec/bin/burncpu/burncpu.go b/exec/bin/burncpu/burncpu.go index 740c456..bfc1064 100644 --- a/exec/bin/burncpu/burncpu.go +++ b/exec/bin/burncpu/burncpu.go @@ -21,12 +21,10 @@ import ( "flag" "fmt" "os" - "os/signal" "path" "runtime" "strconv" "strings" - "syscall" "time" "github.com/chaosblade-io/chaosblade-spec-go/channel" @@ -68,18 +66,7 @@ func main() { bin.PrintErrAndExit(errs) } } else if burnCpuNohup { - go burnCpu() - - // Wait for exit signals - ch := make(chan os.Signal, 1) - signal.Notify(ch, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGKILL) - for s := range ch { - switch s { - case syscall.SIGHUP, syscall.SIGTERM, syscall.SIGKILL, os.Interrupt: - fmt.Println("caught interrupt, exit") - return - } - } + burnCpu() } else { bin.PrintErrAndExit("less --start or --stop flag") } @@ -175,6 +162,7 @@ func burnCpu() { } }() } + select {} } var burnCpuBin = exec.BurnCpuBin @@ -267,7 +255,7 @@ func stopBurnCpu() (success bool, errs string) { if pids == nil || len(pids) == 0 { return true, errs } - response := cl.Run(ctx, "kill", fmt.Sprintf(`-HUP %s`, strings.Join(pids, " "))) + response := cl.Run(ctx, "kill", fmt.Sprintf(`-9 %s`, strings.Join(pids, " "))) if !response.Success { return false, response.Err }