github.com/searKing/golang/go@v1.2.117/syscall/setsid_plan9.go (about)

     1  // Copyright 2022 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package exec
     6  
     7  import "syscall"
     8  
     9  // SysProcAttrSetsid run a program in a new session, is used to detach the process from the parent (normally a shell)
    10  //
    11  // The disowning of a child process is accomplished by executing the system call
    12  // setpgrp() or setsid(), (both of which have the same functionality) as soon as
    13  // the child is forked. These calls create a new process session group, make the
    14  // child process the session leader, and set the process group ID to the process
    15  // ID of the child. https://bsdmag.org/unix-kernel-system-calls/
    16  func SysProcAttrSetsid(attr *syscall.SysProcAttr) {
    17  	// #include "lib.h"
    18  	// #include <unistd.h>
    19  	// #include "sys9.h"
    20  	//
    21  	// pid_t
    22  	// setsid(void)
    23  	// {
    24  	// 	if(_RFORK(RFNAMEG|RFNOTEG) < 0){
    25  	// 		_syserrno();
    26  	// 		return -1;
    27  	//	}
    28  	//	_sessleader = 1;
    29  	//	return getpgrp();
    30  	// }
    31  	// http://9p.io/sources/plan9/sys/src/ape/lib/ap/plan9/setsid.c
    32  	attr.Rfork = syscall.RFNAMEG | syscall.RFNOTEG
    33  }