GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  INN::UTILS::SHLOCK (3)

.ds Aq ’

NAME

INN::Utils::Shlock - Wrapper around the shlock program

CONTENTS

DESCRIPTION

This Perl module wraps the shlock(1) program so that it can easily be used. Calling shlock is more portable than using flock(2) and its corresponding Perl function because this function does not work as expected on all existing systems.

See the shlock(1) documentation for more information.

Using INN::Utils::Shlock is straight-forward:



    use lib <pathnews>/lib/perl;
    use INN::Utils::Shlock;

    my $lockfile = "myprogram.LOCK";

    # Acquire a lock.
    INN::Utils::Shlock::lock($lockfile);

    # Do whatever you want.  The lock prevents concurrent accesses.

    # Unlock.
    INN::Utils::Shlock::unlock($lockfile);



These two functions return 1 on success, 0 on failure. For example, the success of (un)locking can be checked as:



    INN::Utils::Shlock::lock($lockfile) or die "cannot create lock file";



or:



    if (! INN::Utils::Shlock::lock($lockfile, 4)) {
        die "giving up after 4 unsuccessful attempts to create lock file";
    }



Instead of calling unlock(lockfile), the releaselocks() function can be called. It removes any leftover locks, which is useful when several different locks are used. Another possible use is to call it in an END code block:



    END {
        # In case we bail out, while holding a lock.
        INN::Utils::Shlock::releaselocks();
    }



INTERFACE

lock(lockfile) Tries to create a lock file named lockfile.

This function returns 1 on success, 0 on failure.

lock(lockfile, tries) Tries to create a lock file named lockfile. If it fails, locking attempts are repeated once every 2 seconds for at most tries times (including the first unsuccessful attempt).

This function returns 1 on success, 0 on failure.

lock(lockfile, tries, delay) Tries to create a lock file named lockfile. If it fails, locking attempts are repeated once every delay seconds for at most tries times (including the first unsuccessful attempt).

Note that lock(lockfile) is equivalent to lock(lockfile, 1, 2).

This function returns 1 on success, 0 on failure.

releaselocks() Removes all the lock files previously created by calling the lock(lockfile) function.

This function returns the number of removed lock files.

unlock(lockfile) Removes the file named lockfile.

This function returns 1 on success, 0 on failure.

HISTORY

Documentation written by Julien Elie for InterNetNews.

$Id: Shlock.pm.in 9408 2012-05-28 18:42:29Z iulius $

SEE ALSO

perl(1), shlock(1).
Search for    or go to Top of page |  Section 3 |  Main Index


INN 2.6.0 INN::UTILS::SHLOCK (3pm) 2015-09-12

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.