github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/pkg/reexec/command_linux.go (about) 1 package reexec // import "github.com/Prakhar-Agarwal-byte/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 // 21 // As SysProcAttr.Pdeathsig is set, the signal will be sent to the process when 22 // the OS thread which created the process dies. It is the caller's 23 // responsibility to ensure that the creating thread is not terminated 24 // prematurely. See https://go.dev/issue/27505 for more details. 25 func Command(args ...string) *exec.Cmd { 26 return &exec.Cmd{ 27 Path: Self(), 28 Args: args, 29 SysProcAttr: &syscall.SysProcAttr{ 30 Pdeathsig: unix.SIGTERM, 31 }, 32 } 33 }