command_linux.go 639 B

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