Skip to content

Latest commit

 

History

History
57 lines (34 loc) · 1.65 KB

README.rdoc

File metadata and controls

57 lines (34 loc) · 1.65 KB

PidFile

github.com/samullen/pidfile

A basic library for creating lockfiles for processes

This library works with Ruby 1.8 and 1.9 and is licensed under the MIT License.

Installation

The pidfile gem is hosted on RubyGems.org (rubygems.org). This requires that you have rubygems.org in your gem sources.

Install the pidfile gem:

sudo gem install pidfile

Gettings Started

The pidfile gem is easy to use and only requires the instantiation of the pidfile, like so:

pf = PidFile.new

Of course there is other functionality, but if you are just wanting to keep a process from running more than once, this is all you need.

Arguments

PidFile creates file to store the process ID (PID). By default, process ID (PID) files are created in /tmp upon instantiation and are given the same name as the calling script with a .pid extension. Process ID files are removed when the creating program exits.

Each argument, :pidfile and :piddir, can be changed upon instantiation of the class.

Example:

PidFile.new(:piddir => '/var/lock', :pidfile => "awesome.pid")

Miscellaneous

Why isn’t this a singleton?

My main concern is how it would behave when a process is forked multiple times. Each new process would get its own PID, but I wasn’t sure how using a singleton would affect this; if the interrelationship of the processes would keep the object from correctly identifying the correct pidfile.

Anyway, I like the flexibility that not using a singleton offers, and I guess I’d rather ask you not to do something bad rather than restraining you.

Copyright© 2010 Samuel Mullen (samullen). See LICENSE for details