Package lockfile implements a simple automatic lockfile (PID) method for golang.
import "github.com/fredli74/lockfile"
if lock, err := lockfile.Lock(filename); err != nil {
panic(err)
} else {
defer lock.Unlock()
}
func Lock(name string) (*LockFile, error)
Lock automatically checks if the file already exists, if so, reads the process ID from the file and checks if the process is running. If the process is running a nil lock is returned and an error stating "Locked by other process".
func (l *LockFile) Unlock()
Unlock closes and deletes the lock file previously created by Lock()
func ProcessRunning(pid int) bool
ProcessRunning is a cross-platform check to work on both Windows and Unix systems as the os.FindProcess() function works differently.