Add utility to start a child process reaper
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
6b2b1ee576
commit
01e9ac5313
1 changed files with 26 additions and 0 deletions
|
@ -5,9 +5,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const PR_SET_CHILD_SUBREAPER = 36
|
const PR_SET_CHILD_SUBREAPER = 36
|
||||||
|
@ -97,3 +100,26 @@ func dockerRemove(container string) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartReaper starts a goroutine to reap processes
|
||||||
|
func StartReaper() {
|
||||||
|
logrus.Infof("Starting reaper")
|
||||||
|
go func() {
|
||||||
|
sigs := make(chan os.Signal, 10)
|
||||||
|
signal.Notify(sigs, syscall.SIGCHLD)
|
||||||
|
for {
|
||||||
|
// Wait for a child to terminate
|
||||||
|
sig := <-sigs
|
||||||
|
logrus.Infof("Signal received: %v", sig)
|
||||||
|
for {
|
||||||
|
// Reap processes
|
||||||
|
cpid, _ := syscall.Wait4(-1, nil, syscall.WNOHANG, nil)
|
||||||
|
if cpid < 1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("Reaped process with pid %d", cpid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue