Documentation
¶
Overview ¶
Handle pid file based locking.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrBusy = errors.New("Locked by other process") // If you get this, retry after a short sleep might help ErrNeedAbsPath = errors.New("Lockfiles must be given as absolute path names") ErrInvalidPid = errors.New("Lockfile contains invalid pid for system") ErrDeadOwner = errors.New("Lockfile contains pid of process not existent on this system anymore") )
Functions ¶
This section is empty.
Types ¶
type Lockfile ¶
type Lockfile string
Example ¶
lock, err := New(filepath.Join(os.TempDir(), "lock.me.now.lck"))
if err != nil {
fmt.Printf("Cannot init lock. reason: %v\n", err)
panic(err)
}
err = lock.TryLock()
// Error handling is essential, as we only try to get the lock.
if err != nil {
fmt.Printf("Cannot lock \"%v\", reason: %v\n", lock, err)
panic(err)
}
defer lock.Unlock()
fmt.Println("Do stuff under lock")
Output: Do stuff under lock
Click to show internal directories.
Click to hide internal directories.
