Create new session/process grp for forked process

This commit is contained in:
Derek Parker
2015-07-28 12:20:07 -05:00
parent a0115e3a15
commit a6fc8d11a7
3 changed files with 11 additions and 2 deletions

View File

@ -34,6 +34,15 @@ fork_exec(char *argv0, char **argv, int size,
read(fd[0], &sig, 1);
close(fd[0]);
// Create a new session for this process.
if (setsid() < 0) {
// Could not set session, but still want to create
// a new process group.
if (setpgid(0, 0) < 0) {
return -1;
}
}
// Set errno to zero before a call to ptrace.
// It is documented that ptrace can return -1 even
// for successful calls.

View File

@ -98,7 +98,7 @@ func Attach(pid int) (*Process, error) {
}
func (dbp *Process) Kill() (err error) {
err = sys.Kill(dbp.Pid, sys.SIGKILL)
err = sys.Kill(-dbp.Pid, sys.SIGKILL)
if err != nil {
return errors.New("could not deliver signal: " + err.Error())
}

View File

@ -43,7 +43,7 @@ func Launch(cmd []string) (*Process, error) {
proc.Args = cmd
proc.Stdout = os.Stdout
proc.Stderr = os.Stderr
proc.SysProcAttr = &syscall.SysProcAttr{Ptrace: true}
proc.SysProcAttr = &syscall.SysProcAttr{Ptrace: true, Setsid: true}
err = proc.Start()
})
if err != nil {