diff --git a/src/go/rdctl/cmd/internalProcessWaitKill.go b/src/go/rdctl/cmd/internalProcessWaitKill.go index 92cd161568f..b581d21086f 100644 --- a/src/go/rdctl/cmd/internalProcessWaitKill.go +++ b/src/go/rdctl/cmd/internalProcessWaitKill.go @@ -39,7 +39,7 @@ exit, and once it does, terminates all processes within the same process group.` if err != nil { return fmt.Errorf("failed to get process ID: %w", err) } - return process.WaitForProcessAndKillGroup(pid) + return process.KillProcessGroup(pid, true) }, } diff --git a/src/go/rdctl/pkg/process/process_unix.go b/src/go/rdctl/pkg/process/process_unix.go index 3266269ac4a..d86d6255822 100644 --- a/src/go/rdctl/pkg/process/process_unix.go +++ b/src/go/rdctl/pkg/process/process_unix.go @@ -89,10 +89,9 @@ func FindPidOfProcess(executable string) (int, error) { return mainPid, nil } -// Wait for the process identified by the given pid to exit, then kill all -// processes in the same process group. This blocks until the given process -// exits. If the given pid is 0, this is a no-op. -func WaitForProcessAndKillGroup(pid int) error { +// Kill the process group the given process belongs to. If wait is set, block +// until the target process exits first before doing so. +func KillProcessGroup(pid int, wait bool) error { if pid == 0 { return nil } @@ -100,8 +99,10 @@ func WaitForProcessAndKillGroup(pid int) error { if err != nil { return fmt.Errorf("failed to get process group id for %d: %w", pid, err) } - if err = WaitForProcess(pid); err != nil { - return fmt.Errorf("failed to wait for process: %w", err) + if wait { + if err = WaitForProcess(pid); err != nil { + return fmt.Errorf("failed to wait for process: %w", err) + } } err = unix.Kill(-pgid, unix.SIGTERM) if err != nil && !errors.Is(err, unix.ESRCH) { diff --git a/src/go/rdctl/pkg/process/process_windows.go b/src/go/rdctl/pkg/process/process_windows.go index d0edd6fa8b6..16475400060 100644 --- a/src/go/rdctl/pkg/process/process_windows.go +++ b/src/go/rdctl/pkg/process/process_windows.go @@ -412,11 +412,10 @@ func FindPidOfProcess(executable string) (int, error) { return mainPid, nil } -// Wait for the process identified by the given pid to exit, then kill all -// processes in the same process group. This blocks until the given process -// exits. -func WaitForProcessAndKillGroup(pid int) error { - return errors.New("WaitForProcessAndKillGroup is not implemented on Windows") +// Kill the process group the given process belongs to. If wait is set, block +// until the target process exits first before doing so. +func KillProcessGroup(pid int, wait bool) error { + return errors.New("KillProcessGroup is not implemented on Windows") } // TerminateProcessInDirectory terminates all processes where the executable diff --git a/src/go/rdctl/pkg/shutdown/shutdown.go b/src/go/rdctl/pkg/shutdown/shutdown.go index 558fbe062ba..9c048e9255e 100644 --- a/src/go/rdctl/pkg/shutdown/shutdown.go +++ b/src/go/rdctl/pkg/shutdown/shutdown.go @@ -246,7 +246,7 @@ func terminateRancherDesktopFunc(appDir string) func(context.Context) error { if err != nil { return err } - return process.WaitForProcessAndKillGroup(pid) + return process.KillProcessGroup(pid, false) })()) errors = multierror.Append(errors, process.TerminateProcessInDirectory(appDir, true))