Skip to content

Commit

Permalink
use process group.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Sep 7, 2021
1 parent 7795bb1 commit f004def
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions hls/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ func (m *ManagerCtx) Start() error {
read, write := io.Pipe()
m.cmd.Stdout = write

m.cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGINT,
}
//create a new process group
m.cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}

m.active = false
m.lastRequest = time.Now()
Expand Down Expand Up @@ -167,8 +166,15 @@ func (m *ManagerCtx) Stop() {
close(m.shutdown)

if m.cmd.Process != nil {
err := m.cmd.Process.Kill()
m.logger.Err(err).Msg("killing proccess")
pgid, err := syscall.Getpgid(m.cmd.Process.Pid)
if err == nil {
err := syscall.Kill(-pgid, syscall.SIGKILL)
m.logger.Err(err).Msg("killing proccess group")
} else {
m.logger.Err(err).Msg("could not get proccess group id")
err := m.cmd.Process.Kill()
m.logger.Err(err).Msg("killing proccess")
}
m.cmd = nil
}

Expand Down

0 comments on commit f004def

Please sign in to comment.