From 33d4f397b5a2139ef8e3c3911860bcd949a2aabe Mon Sep 17 00:00:00 2001 From: nixpig <143995476+nixpig@users.noreply.github.com> Date: Fri, 27 Dec 2024 05:01:22 +0000 Subject: [PATCH] fix: get pid of container directly --- container/container_delete.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/container/container_delete.go b/container/container_delete.go index 31d82c0..f717ed5 100644 --- a/container/container_delete.go +++ b/container/container_delete.go @@ -4,9 +4,9 @@ import ( "fmt" "os" "path/filepath" + "syscall" "github.com/nixpig/brownie/cgroups" - "golang.org/x/sys/unix" ) func (c *Container) Delete(force bool) error { @@ -14,8 +14,12 @@ func (c *Container) Delete(force bool) error { return fmt.Errorf("container cannot be deleted in current state (%s)", c.Status()) } - if err := c.Kill(unix.SIGKILL); err != nil { - return fmt.Errorf("send sigkill to container: %w", err) + process, err := os.FindProcess(c.PID()) + if err != nil { + return fmt.Errorf("find container process (%d): %w", c.PID(), err) + } + if process != nil { + process.Signal(syscall.Signal(9)) } if err := cgroups.DeleteV1(c.Spec.Linux.CgroupsPath); err != nil {