Skip to content

Package lockfile implements a simple automatic lockfile (PID) method for golang.

License

Notifications You must be signed in to change notification settings

fredli74/lockfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lockfile

Package lockfile implements a simple automatic lockfile (PID) method for golang.

Build Status

Usage

import "github.com/fredli74/lockfile"

Example

    if lock, err := lockfile.Lock(filename); err != nil {
        panic(err)
    } else {
        defer lock.Unlock()
    }

Reference

func Lock

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 (*LockFile) Unlock

func (l *LockFile) Unlock()

Unlock closes and deletes the lock file previously created by Lock()

func ProcessRunning

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.

About

Package lockfile implements a simple automatic lockfile (PID) method for golang.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages