So I am writing a small utility which should be able to update itself (replace it's own binary).
The best way to do this on Windows seems to be:
- Download the new version of the binary as my.exe.new
- my.exes runs my.exe.new and exits
- my.exe.new waits for my.exe to exit
- my.exe.new copies itself as my.exe
- my.exe.new starts another copy of itself as my.exe and exits
- my.exe waits for my.exe.new to exit
- my.exe removes my.exe.new
Now for all of this to work I have to be able to synchronize the state between the processes (being able to know when the parent has exited), but it seems that os.Getppid (nor syscall.Getppid) in golang Windows is not implemented as it always returns -1.
I've seen that patches are underway, but I am not willing to patch my standard libraries.
Is there an easy way to make Getppid working on even older versions of Go (perhaps reimplementing it?), or perhaps anyone can suggest a better method of synchronizing between the process state?
The thing which comes to mind is binding on a socket, but thats a big hacky.
Perhaps passing a pipe to the child process, and the child waiting for the pipe to close?