Skip to content

Commit

Permalink
fixbug: Under some systems, processes cannot exit using kill -HUP
Browse files Browse the repository at this point in the history
Signed-off-by: tiny.x <185120555@qq.com>
  • Loading branch information
tiny-x authored and xcaspar committed Nov 17, 2020
1 parent 97785d6 commit f72b2b0
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions exec/bin/burncpu/burncpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"path"
"runtime"
"strconv"
"strings"
"syscall"
"time"

"github.com/chaosblade-io/chaosblade-spec-go/channel"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -175,6 +162,7 @@ func burnCpu() {
}
}()
}
select {}
}

var burnCpuBin = exec.BurnCpuBin
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f72b2b0

Please sign in to comment.