lockfile

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2018 License: MIT Imports: 4 Imported by: 0

README

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.

Documentation

Overview

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

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

Index

Constants

This section is empty.

Variables

View Source
var AlreadyLocked = errors.New("Locked by other process")

Functions

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.

Types

type LockFile

type LockFile struct {
	// contains filtered or unexported fields
}

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()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL