Skip to content

Commit 7275617

Browse files
authored
Clean up native subprocess is main process dies (#19)
1 parent a9767b6 commit 7275617

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

native.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/exec"
1313
"sync"
14+
"syscall"
1415
"time"
1516

1617
"github.com/pion/webrtc/v4/pkg/media"
@@ -224,6 +225,12 @@ func ExtractAndRunNativeBin() error {
224225
cmd.Stdout = os.Stdout
225226
cmd.Stderr = os.Stderr
226227

228+
// Set the process group ID so we can kill the process and its children when this process exits
229+
cmd.SysProcAttr = &syscall.SysProcAttr{
230+
Setpgid: true,
231+
Pdeathsig: syscall.SIGKILL,
232+
}
233+
227234
// Start the command
228235
if err := cmd.Start(); err != nil {
229236
return fmt.Errorf("failed to start binary: %w", err)

0 commit comments

Comments
 (0)