NAME

PidFile - simple read / write pidfile

SYNOPSIS

use PidFile;

# read pidfile
my $pid = PidFile->Read;

if ( $pid ) {
    # pid file for this script arealdy exists

    # check if script running
    if ( PidFile->Check( "pid" => $pid ) {

        # script running, so i die
        confess;
    }

    # script not running, delete old pidfile
    PidFile->Delete;
}

# save new pid file
PidFile->Write;


## or you can run just only

PidFile->Write;

## and this function check if old pidfile exists and if script running

DESCRIPTION

PidFile provide very simple class methods to manages a pidfile for the current or any process.

CLASS METHODS

Path

get path to pid file

input (hash):

name => (str) script name [ default: $FindBin::Script ]

return: path to pid file

Read

read pid from pid file

input (hash):

name => (str) script name [ default: $FindBin::Script ]

return: pid from pidfile or undef if pidfile not exists

Write

write pid to pid file

input (hash):

pid => (int) process id [ default: $$ ]

name => (str) script name [ default: $FindBin::Script ]

return: 1 upon successfully writing the file or undef if it encountered an error

Delete

delete pid file

input (hash):

name => (str) script name [ default: $FindBin::Script ]

return: 1 if file successfully deleted, else 0

Check

check if process running

input (hash):

pid => (int) process id [ default: $$ ]

name => (str) script name [ optional ]

return: pid if proces exists, undef if error, else 0

CLASS ATTRIBUTES

Dir

set / get pid file dir

default: /var/run

Suffix

set / get pidfile suffix

default: empty sting

AUTHOR

Lukasz Romanowski (roman) <lroman@cpan.org>

LICENSE

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