lockfile

package module
v0.0.0-...-92f5e1e 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: 5 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址