github.com/hernad/nomad@v1.6.112/drivers/shared/executor/utils_unix.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
     5  // +build darwin dragonfly freebsd linux netbsd openbsd solaris
     6  
     7  package executor
     8  
     9  import (
    10  	"os/exec"
    11  	"syscall"
    12  )
    13  
    14  // isolateCommand sets the setsid flag in exec.Cmd to true so that the process
    15  // becomes the process leader in a new session and doesn't receive signals that
    16  // are sent to the parent process.
    17  func isolateCommand(cmd *exec.Cmd) {
    18  	if cmd.SysProcAttr == nil {
    19  		cmd.SysProcAttr = &syscall.SysProcAttr{}
    20  	}
    21  	cmd.SysProcAttr.Setsid = true
    22  }