# zyc @ DESKTOP-KK42M35 in /mnt/d/GoProject/src/MyDocker on git:master x [17:29:55] $ go run main.go os.Args = [/tmp/go-build3043439324/b001/exe/main] ParentProcess os.Args = [childProcess] ChildProcess
var registeredInitializers = make(map[string]func())
// Register adds an initialization func under the specified name funcRegister(name string, initializer func()) { if _, exists := registeredInitializers[name]; exists { panic(fmt.Sprintf("reexec func already registered under name %q", name)) }
registeredInitializers[name] = initializer }
// Init is called as the first part of the exec process and returns true if an // initialization function was called. funcInit()bool { initializer, exists := registeredInitializers[os.Args[0]] if exists { initializer()
// Self returns the path to the current process's binary. // Returns "/proc/self/exe". funcSelf()string { return"/proc/self/exe" }
// Command returns *exec.Cmd which has Path as current binary. Also it setting // This will use the in-memory version (/proc/self/exe) of the current binary, // it is thus safe to delete or replace the on-disk binary (os.Args[0]). funcCommand(args ...string) *exec.Cmd { return &exec.Cmd{ Path: Self(), Args: args, } }