Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable setting pgid #79

Open
chensk opened this issue Mar 14, 2022 · 0 comments
Open

enable setting pgid #79

chensk opened this issue Mar 14, 2022 · 0 comments

Comments

@chensk
Copy link

chensk commented Mar 14, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant