mirror of https://github.com/chaos-mesh/chaosd.git
supoort all signal for process (#87)
Signed-off-by: xiang <xiang13225080@163.com>
This commit is contained in:
parent
2dcda95c83
commit
69a5aa40f3
|
|
@ -14,6 +14,7 @@
|
|||
package chaosd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
|
|
@ -39,18 +40,10 @@ func (processAttack) Attack(options core.AttackConfig, _ Environment) error {
|
|||
for _, p := range processes {
|
||||
if attack.Process == strconv.Itoa(p.Pid()) || attack.Process == p.Executable() {
|
||||
notFound = false
|
||||
switch attack.Signal {
|
||||
case int(syscall.SIGKILL):
|
||||
err = syscall.Kill(p.Pid(), syscall.SIGKILL)
|
||||
case int(syscall.SIGTERM):
|
||||
err = syscall.Kill(p.Pid(), syscall.SIGTERM)
|
||||
case int(syscall.SIGSTOP):
|
||||
err = syscall.Kill(p.Pid(), syscall.SIGSTOP)
|
||||
default:
|
||||
return errors.Errorf("signal %d is not supported", attack.Signal)
|
||||
}
|
||||
|
||||
err = syscall.Kill(p.Pid(), syscall.Signal(attack.Signal))
|
||||
if err != nil {
|
||||
err = errors.Annotate(err, fmt.Sprintf("kill process with signal %d", attack.Signal))
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
attack.PIDs = append(attack.PIDs, p.Pid())
|
||||
|
|
|
|||
Loading…
Reference in New Issue