feat(orphans): add gt orphans kill command

Adds command to find and terminate orphan claude processes with PPID=1.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
mayor
2026-01-21 18:03:51 -08:00
committed by beads/crew/emma
parent d0e49a216a
commit 6e2169de7f

View File

@@ -467,6 +467,12 @@ func runOrphansKill(cmd *cobra.Command, args []string) error {
// Kill orphaned processes // Kill orphaned processes
if len(procOrphans) > 0 { if len(procOrphans) > 0 {
fmt.Printf("\nKilling orphaned processes...\n") fmt.Printf("\nKilling orphaned processes...\n")
// Use SIGKILL with --force for immediate termination, SIGTERM otherwise
signal := syscall.SIGTERM
if orphansKillForce {
signal = syscall.SIGKILL
}
var killed, failed int var killed, failed int
for _, o := range procOrphans { for _, o := range procOrphans {
proc, err := os.FindProcess(o.PID) proc, err := os.FindProcess(o.PID)
@@ -476,7 +482,7 @@ func runOrphansKill(cmd *cobra.Command, args []string) error {
continue continue
} }
if err := proc.Signal(syscall.SIGTERM); err != nil { if err := proc.Signal(signal); err != nil {
if err == os.ErrProcessDone { if err == os.ErrProcessDone {
fmt.Printf(" %s PID %d: already terminated\n", style.Dim.Render("○"), o.PID) fmt.Printf(" %s PID %d: already terminated\n", style.Dim.Render("○"), o.PID)
continue continue
@@ -712,6 +718,12 @@ func runOrphansKillProcesses(cmd *cobra.Command, args []string) error {
} }
// Kill the processes // Kill the processes
// Use SIGKILL with --force for immediate termination, SIGTERM otherwise
signal := syscall.SIGTERM
if orphansProcsForce {
signal = syscall.SIGKILL
}
var killed, failed int var killed, failed int
for _, o := range orphans { for _, o := range orphans {
proc, err := os.FindProcess(o.PID) proc, err := os.FindProcess(o.PID)
@@ -721,8 +733,7 @@ func runOrphansKillProcesses(cmd *cobra.Command, args []string) error {
continue continue
} }
// Send SIGTERM first for graceful shutdown if err := proc.Signal(signal); err != nil {
if err := proc.Signal(syscall.SIGTERM); err != nil {
// Process may have already exited // Process may have already exited
if err == os.ErrProcessDone { if err == os.ErrProcessDone {
fmt.Printf(" %s PID %d: already terminated\n", style.Dim.Render("○"), o.PID) fmt.Printf(" %s PID %d: already terminated\n", style.Dim.Render("○"), o.PID)
@@ -784,6 +795,12 @@ func runOrphansKillProcessesAggressive() error {
} }
// Kill the processes // Kill the processes
// Use SIGKILL with --force for immediate termination, SIGTERM otherwise
signal := syscall.SIGTERM
if orphansProcsForce {
signal = syscall.SIGKILL
}
var killed, failed int var killed, failed int
for _, z := range zombies { for _, z := range zombies {
proc, err := os.FindProcess(z.PID) proc, err := os.FindProcess(z.PID)
@@ -793,8 +810,7 @@ func runOrphansKillProcessesAggressive() error {
continue continue
} }
// Send SIGTERM first for graceful shutdown if err := proc.Signal(signal); err != nil {
if err := proc.Signal(syscall.SIGTERM); err != nil {
// Process may have already exited // Process may have already exited
if err == os.ErrProcessDone { if err == os.ErrProcessDone {
fmt.Printf(" %s PID %d: already terminated\n", style.Dim.Render("○"), z.PID) fmt.Printf(" %s PID %d: already terminated\n", style.Dim.Render("○"), z.PID)