github.com/searKing/golang/go@v1.2.117/syscall/setsid_windows.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 (
     8  	"syscall"
     9  
    10  	"golang.org/x/sys/windows"
    11  )
    12  
    13  // SysProcAttrSetsid run a program in a new session, is used to detach the process from the parent (normally a shell)
    14  func SysProcAttrSetsid(attr *syscall.SysProcAttr) {
    15  	// CREATE_NEW_PROCESS_GROUP: The new process is the root process of a new process group. The process group includes all processes that are descendants of this root process.
    16  	// 	The process identifier of the new process group is the same as the process identifier,
    17  	// 	which is returned in the lpProcessInformation parameter.
    18  	//  If this flag is specified, CTRL+C signals will be disabled for all processes within the new process group.
    19  	// DETACHED_PROCESS: For console processes, the new process does not inherit its parent's console (the default).
    20  	// https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
    21  	attr.CreationFlags = syscall.CREATE_NEW_PROCESS_GROUP | windows.DETACHED_PROCESS
    22  	attr.HideWindow = true
    23  }