fix(process): terminate unmanaged pids with sigterm

This commit is contained in:
Virgil 2026-04-04 01:40:53 +00:00
parent 4b1013a023
commit c5adc8066e
2 changed files with 10 additions and 3 deletions

View file

@ -407,7 +407,7 @@ func (s *Service) Kill(id string) error {
return nil
}
// KillPID forcefully terminates a process by operating-system PID.
// KillPID terminates a process by operating-system PID.
//
// Example:
//
@ -428,7 +428,7 @@ func (s *Service) KillPID(pid int) error {
return nil
}
if err := syscall.Kill(pid, syscall.SIGKILL); err != nil {
if err := syscall.Kill(pid, syscall.SIGTERM); err != nil {
return coreerr.E("Service.KillPID", fmt.Sprintf("failed to signal pid %d", pid), err)
}

View file

@ -5,6 +5,7 @@ import (
"os/exec"
"strings"
"sync"
"syscall"
"testing"
"time"
@ -467,7 +468,7 @@ func TestService_Kill(t *testing.T) {
}
func TestService_KillPID(t *testing.T) {
t.Run("force kills unmanaged process", func(t *testing.T) {
t.Run("terminates unmanaged process with SIGTERM", func(t *testing.T) {
svc, _ := newTestService(t)
cmd := exec.Command("sleep", "60")
@ -494,6 +495,12 @@ func TestService_KillPID(t *testing.T) {
select {
case err := <-waitCh:
require.Error(t, err)
var exitErr *exec.ExitError
require.ErrorAs(t, err, &exitErr)
ws, ok := exitErr.Sys().(syscall.WaitStatus)
require.True(t, ok)
assert.True(t, ws.Signaled())
assert.Equal(t, syscall.SIGTERM, ws.Signal())
case <-time.After(2 * time.Second):
t.Fatal("unmanaged process should have been killed")
}