Skip to content

Single Instance: keep just one instance of your program

License

Notifications You must be signed in to change notification settings

Miguel-Dorta/si

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

si

Single Instance: keep just one instance of your program.

Build Status GoDoc

Description

si is a Go(Lang) package that helps you to find and communicate with other instances of your program.

Example

package main

import (
	"fmt"
	"github.com/Miguel-Dorta/si"
	"os"
)

func main() {
	// Example 1: Register your instance and exit if there's another one running
	if err := si.Register("my awesome program"); err != nil {
		if err == si.ErrOtherInstanceRunning {
			fmt.Println("There's another instance running, bye!")
			os.Exit(0)
		}
		fmt.Println("Error registering instance: " + err.Error())
		os.Exit(1)
	}

	// Example 2: Find another instance and kill it
	p, err := si.Find("my awesome program")
	if err != nil {
		fmt.Println("Error finding another instance: " + err.Error())
		os.Exit(1)
	}
	if p == nil {
		fmt.Println("No other instance was found, bye!")
		os.Exit(0)
	}
	p.process.Kill()
}

Important

If you want to communicate with your program using si.Process.StdXPipe(), this should have a pipe asigned to its stdX, else it will have /dev/null as default. This makes impossible the communication between processes. See si/test/test.go/createInstance2() to see an example.

Meme

meme of a mexican dog saying "si"

About

Single Instance: keep just one instance of your program

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages