mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-03 23:26:36 +08:00
edit process kill
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -320,6 +321,10 @@ func (p *ProcessBase) initPsutil() {
|
||||
}
|
||||
|
||||
func (p *ProcessBase) Kill() error {
|
||||
if p.State.State != eum.ProcessStateRunning {
|
||||
return errors.New("can't kill not running process")
|
||||
}
|
||||
p.State.manualStopFlag = true
|
||||
p.op.Signal(syscall.SIGINT)
|
||||
select {
|
||||
case <-p.StopChan:
|
||||
|
@@ -37,10 +37,6 @@ func (p *processCtlLogic) KillProcess(uuid int) error {
|
||||
if !ok {
|
||||
return errors.New("进程类型错误")
|
||||
}
|
||||
if result.State.State != eum.ProcessStateRunning {
|
||||
return nil
|
||||
}
|
||||
result.State.manualStopFlag = true
|
||||
return result.Kill()
|
||||
}
|
||||
|
||||
@@ -61,13 +57,9 @@ func (p *processCtlLogic) KillAllProcess() {
|
||||
wg := sync.WaitGroup{}
|
||||
p.processMap.Range(func(key, value any) bool {
|
||||
process := value.(*ProcessBase)
|
||||
if process.State.State != eum.ProcessStateRunning {
|
||||
return true
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
process.State.manualStopFlag = true
|
||||
process.Kill()
|
||||
}()
|
||||
return true
|
||||
|
@@ -61,7 +61,6 @@ var OperationHandle = map[eum.TaskOperation]operationFunc{
|
||||
return false
|
||||
}
|
||||
log.Logger.Debugw("异步停止任务", "proc", proc.Name)
|
||||
proc.State.manualStopFlag = true
|
||||
go proc.Kill()
|
||||
return true
|
||||
},
|
||||
@@ -72,7 +71,6 @@ var OperationHandle = map[eum.TaskOperation]operationFunc{
|
||||
return false
|
||||
}
|
||||
log.Logger.Debugw("停止任务并等待结束", "proc", proc.Name)
|
||||
proc.State.manualStopFlag = true
|
||||
return proc.Kill() == nil
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user