I know this topic is a bit old, but I needed it recently on Windows and I'll post here how I did it in case someone else needs.
I used Windows mutex as described by ankurg...@gmail.com: var ( kernel32 = syscall.NewLazyDLL("kernel32.dll") procCreateMutex = kernel32.NewProc("CreateMutexW") ) func CreateMutex(name string) (uintptr, error) { ret, _, err := procCreateMutex.Call( 0, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(name))), ) switch int(err.(syscall.Errno)) { case 0: return ret, nil default: return ret, err } } // mutexName starting with "Global\" will work across all user sessions _, err := CreateMutex("SomeMutexName") I created a lib with a more complete example: https://github.com/rodolfoag/gow32 Thx! Em sábado, 4 de junho de 2016 11:30:14 UTC-3, ankurgu...@gmail.com escreveu: > > The simplest solution would be to do it using MUTEX, here is how to do it > <http://getgoingit.blogspot.in/2016/06/restrict-desktop-application-to-single.html> > along > with description. > > On Wednesday, 22 January 2014 09:22:34 UTC+5:30, Shark Flh wrote: >> >> how to restrict the program run only one instance >> what method can work on windows and Linux both system? >> >> for example I have a program test.exe, I copy it to 2 dir >> a/test.exe >> b/test.exe >> I want restrict the test.exe can only run one instance from each dir. >> >> i tried open file use ModeExclusive,but it doesn't on windows. >> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.