feat(acp): supervisor spawn / handshake / monitor / kill / onExit

This commit is contained in:
2026-05-07 14:01:04 +08:00
parent b4694e113b
commit 70c86a552b
3 changed files with 324 additions and 2 deletions
+23
View File
@@ -0,0 +1,23 @@
//go:build !windows
package acp
import (
"syscall"
"time"
)
// unixGracefulTerm 在 Unix 平台上先发 SIGTERM,等待 grace 时间内退出;
// 否则 Process.Kill。done channel 由 monitorProcess 关闭。
func (s *Supervisor) unixGracefulTerm(proc *Process, grace time.Duration) {
if proc.Cmd.Process == nil {
return
}
_ = proc.Cmd.Process.Signal(syscall.SIGTERM)
select {
case <-proc.done:
return
case <-time.After(grace):
_ = proc.Cmd.Process.Kill()
}
}