go-daemon
go-daemon copied to clipboard
enable setting pgid
After reborn, the new process get pgid
the same as it's process id by default. I need to be able to customize the pgid so that I could kill it nicely since the reborn process becomes an orphan process.
By the way, directly calling to syscall.Setpgid
would fail: operation not permitted
pgid, _ := syscall.Getpgid(os.Getpid())
cntxt := &daemon.Context{
Umask: 027,
Env: append(os.Environ(), "PGID="+strconv.Itoa(pgid)),
}
d, _ := cntxt.Reborn()
defer cntxt.Release()
for _, k := range os.Environ() {
if strings.HasPrefix(k, "PGID=") {
pgid, _ := strconv.Atoi(strings.Split(k, "=")[1])
if err := syscall.Setpgid(os.Getpid(), pgid); err != nil {
panic("fail to set pgid")
}
}
}
I'm wondering if there is any way to achieve what I need?