pidfile
pidfile copied to clipboard
Simple library to create a PID locking file for processes which need to worry about that sort of thing
= PidFile
http://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 (http://rubygems.org). This requires that you have http://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
Copyright(c) 2010 Samuel Mullen (samullen). See LICENSE for details