github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/reexec/command_linux.go (about)

     1  // +build linux
     2  
     3  package reexec
     4  
     5  import (
     6  	"os/exec"
     7  	"syscall"
     8  
     9  	"golang.org/x/sys/unix"
    10  )
    11  
    12  // Self returns the path to the current process's binary.
    13  // Returns "/proc/self/exe".
    14  func Self() string {
    15  	return "/proc/self/exe"
    16  }
    17  
    18  // Command returns *exec.Cmd which has Path as current binary. Also it setting
    19  // SysProcAttr.Pdeathsig to SIGTERM.
    20  // This will use the in-memory version (/proc/self/exe) of the current binary,
    21  // it is thus safe to delete or replace the on-disk binary (os.Args[0]).
    22  func Command(args ...string) *exec.Cmd {
    23  	return &exec.Cmd{
    24  		Path: Self(),
    25  		Args: args,
    26  		SysProcAttr: &syscall.SysProcAttr{
    27  			Pdeathsig: unix.SIGTERM,
    28  		},
    29  	}
    30  }