Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixbug: Under some systems, processes cannot exit using kill -HUP #67

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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