Proc::PID_File - check whether a self process is already running


NAME

Proc::PID_File - check whether a self process is already running


SYNOPSIS

 use Proc::PID_File;
 # example 1. a nonforking program that just wants to check whether its
 # instance is already running.
 die "Already running!\n" if
        hold_pid_file("/tmp/grab_lots_of_news_headlines.pid");
 # ...code...
 exit; # pid file will be automatically removed here
 # example 2. a forking program (the daemon is the child and the parent
 # immediately exists). it wants to check whether its instance is already
 # running.
 die "Already running!\n" if
        hold_pid_file("/var/run/mydaemon.pid");
 fork && {
        # the parent part
        release_the_pid_file();
        exit; # pid file won't be removed here
 }
 # the child part
 # ...code...
 exit; # pid file will be automatically removed here
 # example 3. a forking program (the parent stays active, launches children
 # to serve requests. children exit after serving some requests). it wants
 # to check whether its instance is already running.
 die "Already running!\n" if
   hold__pid_file("/var/run/mydaemon.pid");
 while (1) {
        if ($request = get_request()) {
                if (fork()==0) {
                        # the child part
                        release_the_pid_file();
                        # ...code...
                        exit; # pid file won't be removed here
                }
        }
 exit; # pid file will be removed here


DESCRIPTION

A pid file is a file that contain, guess what, pid. Pids are written down to files so that:

This module can be used so that your script can do the former.


FUNCTIONS


AUTHOR

Copyright (C) 2000-2002, Steven Haryanto <steven@haryan.to>. All rights reserved.

This module is free software; you may redistribute it and/or modify it under the same terms as Perl itself.


HISTORY

See Changes.

 Proc::PID_File - check whether a self process is already running