Skip to content

Commit 69a5aa4

Browse files
supoort all signal for process (#87)
Signed-off-by: xiang <[email protected]>
1 parent 2dcda95 commit 69a5aa4

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

pkg/server/chaosd/process.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package chaosd
1515

1616
import (
17+
"fmt"
1718
"strconv"
1819
"syscall"
1920

@@ -39,18 +40,10 @@ func (processAttack) Attack(options core.AttackConfig, _ Environment) error {
3940
for _, p := range processes {
4041
if attack.Process == strconv.Itoa(p.Pid()) || attack.Process == p.Executable() {
4142
notFound = false
42-
switch attack.Signal {
43-
case int(syscall.SIGKILL):
44-
err = syscall.Kill(p.Pid(), syscall.SIGKILL)
45-
case int(syscall.SIGTERM):
46-
err = syscall.Kill(p.Pid(), syscall.SIGTERM)
47-
case int(syscall.SIGSTOP):
48-
err = syscall.Kill(p.Pid(), syscall.SIGSTOP)
49-
default:
50-
return errors.Errorf("signal %d is not supported", attack.Signal)
51-
}
5243

44+
err = syscall.Kill(p.Pid(), syscall.Signal(attack.Signal))
5345
if err != nil {
46+
err = errors.Annotate(err, fmt.Sprintf("kill process with signal %d", attack.Signal))
5447
return errors.WithStack(err)
5548
}
5649
attack.PIDs = append(attack.PIDs, p.Pid())

0 commit comments

Comments
 (0)