github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/reexec/command_linux.go (about)

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