github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/pkg/reexec/command_linux.go (about)

     1  package reexec // import "github.com/docker/docker/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  }