@@ -22,7 +22,6 @@ import (
2222 "os"
2323 "os/exec"
2424 "path/filepath"
25- "runtime"
2625 "strconv"
2726 "strings"
2827 "time"
@@ -656,17 +655,16 @@ func killProcess(path string) error {
656655 return nil
657656}
658657
659- // trySigKillProcess attempts to terminate a process by PID in a cross-platform way.
660- // It first confirms the pid belongs to a minikube process (best-effort heuristic).
661- // On Windows, if os.Process.Kill fails (common for some exited or protected processes),
662- // it falls back to invoking taskkill.
658+ // trySigKillProcess takes a PID as argument and tries to SIGKILL it.
659+ // It performs an ownership check of the pid,
660+ // before trying to send a sigkill signal to it
663661func trySigKillProcess (pid int ) error {
664662 itDoes , err := isMinikubeProcess (pid )
665663 if err != nil {
666664 return err
667665 }
666+
668667 if ! itDoes {
669- // Not a minikube process; report as stale (kept as error for existing caller semantics)
670668 return fmt .Errorf ("stale pid: %d" , pid )
671669 }
672670
@@ -677,25 +675,6 @@ func trySigKillProcess(pid int) error {
677675
678676 klog .Infof ("Killing pid %d ..." , pid )
679677 if err := proc .Kill (); err != nil {
680- // Benign / already gone cases (Unix & Go 1.20+)
681- lower := strings .ToLower (err .Error ())
682- if errors .Is (err , os .ErrProcessDone ) ||
683- strings .Contains (lower , "no such process" ) ||
684- strings .Contains (lower , "already finished" ) {
685- klog .Infof ("process %d already exited" , pid )
686- return nil
687- }
688-
689- // Windows fallback: taskkill (handles some cases where Kill fails)
690- if runtime .GOOS == "windows" {
691- klog .Infof ("os.Process.Kill failed for %d with %v - attempting taskkill" , pid , err )
692- cmd := exec .Command ("taskkill" , "/PID" , strconv .Itoa (pid ), "/F" , "/T" )
693- if tkErr := cmd .Run (); tkErr == nil {
694- return nil
695- }
696- return errors .Wrapf (err , "failed killing pid %d (taskkill also failed)" , pid )
697- }
698-
699678 klog .Infof ("Kill failed with %v - removing probably stale pid..." , err )
700679 return errors .Wrapf (err , "removing likely stale unkillable pid: %d" , pid )
701680 }
0 commit comments