command_linux.go 662 B

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