mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-09-21 00:40:46 +02:00
feat: manage task process lifetimes and preserve turn history
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func prepareShellCmdSession(cmd *exec.Cmd) error {
|
||||
@@ -29,7 +31,9 @@ func terminateProcessGroup(rootPID int, cmd *exec.Cmd) {
|
||||
if pid <= 0 {
|
||||
return
|
||||
}
|
||||
tk := exec.Command("taskkill", "/F", "/T", "/PID", strconv.Itoa(pid))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
tk := exec.CommandContext(ctx, "taskkill", "/F", "/T", "/PID", strconv.Itoa(pid))
|
||||
if err := tk.Run(); err != nil {
|
||||
if cmd != nil && cmd.Process != nil {
|
||||
_ = cmd.Process.Kill()
|
||||
@@ -41,3 +45,12 @@ func terminateProcessGroup(rootPID int, cmd *exec.Cmd) {
|
||||
func terminateCmdTree(cmd *exec.Cmd) {
|
||||
terminateProcessGroup(0, cmd)
|
||||
}
|
||||
|
||||
func stopProcessGroup(pid int, cmd *exec.Cmd) {
|
||||
// Windows has no portable SIGTERM equivalent for arbitrary console jobs.
|
||||
terminateProcessGroup(pid, cmd)
|
||||
}
|
||||
|
||||
// Windows taskkill /T is best effort; unlike a Unix PGID it has no persistent
|
||||
// group handle to query after the root exits. Job Objects are needed for that.
|
||||
func processGroupExists(pid int) bool { return false }
|
||||
|
||||
Reference in New Issue
Block a user