From 727561738ef1c220e2e1184b599f709a30e489f1 Mon Sep 17 00:00:00 2001 From: Brandon Tuttle <11356668+tutman96@users.noreply.github.com> Date: Tue, 11 Feb 2025 08:55:02 -0500 Subject: [PATCH] Clean up native subprocess is main process dies (#19) --- native.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/native.go b/native.go index 89e6803..d34ab07 100644 --- a/native.go +++ b/native.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "sync" + "syscall" "time" "github.com/pion/webrtc/v4/pkg/media" @@ -224,6 +225,12 @@ func ExtractAndRunNativeBin() error { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr + // Set the process group ID so we can kill the process and its children when this process exits + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + Pdeathsig: syscall.SIGKILL, + } + // Start the command if err := cmd.Start(); err != nil { return fmt.Errorf("failed to start binary: %w", err)