You will already find advisory locks in many different systems and languages as "flock".
Code:
$ man 2 flock
FLOCK(2) Linux Programmer's Manual FLOCK(2)
NAME
flock - apply or remove an advisory lock on an open file
SYNOPSIS
#include <sys/file.h>
int flock(int fd, int operation);
DESCRIPTION
Apply or remove an advisory lock on the open file specified by fd. The
argument operation is one of the following:
LOCK_SH Place a shared lock. More than one process may hold a
shared lock for a given file at a given time.
LOCK_EX Place an exclusive lock. Only one process may hold an
exclusive lock for a given file at a given time.
LOCK_UN Remove an existing lock held by this process.
A call to flock() may block if an incompatible lock is held by
another process. To make a nonblocking request, include LOCK_NB
(by ORing) with any of the above operations.
...
$ perldoc -f flock
flock FILEHANDLE,OPERATION
Calls flock(2), or an emulation of it, on FILEHANDLE. Returns
true for success, false on failure. Produces a fatal error if
used on a machine that doesn't implement flock(2), fcntl(2)
locking, or lockf(3). "flock" is Perl's portable file locking
interface, although it locks only entire files, not records.
...
how can I lock my keyboard while I'm away from the computer without using lock command. What other commands gives me the option to lock keyboard device?
thanks (7 Replies)
When I want to use the editor ,whether vi or textedit,it prompts for entering a key. How can I disable this function?many thanks for offering solutions! (1 Reply)
I only able to lock user ID with passwd -l username
It seems there is no option for me to unlock ID in solaris?
Is there any command as below?
passwd -u username
Appreciate someome can share with me the way to do it. (1 Reply)
When I do HMC upgrade, I download HMC code from IBM web site and burn it to a DVD disk, when I get the first DVD out of HMC's dvd rom and input the second DVD, it shows error:
The requested device is already locked by the process: Install Corrective Service.
Would you like to try to request a... (2 Replies)
We have two processes, one which copies a control file into a folder and another which is polling this folder and reading the control files.
Sometimes they clash and the reader fails because the copy is still happening.
We have been told that we should change the copy to a move because the... (1 Reply)
Hello all,
If anyone has time, I have a few questions:
How do I do the following in Linux. We are using Red Hat and Oracle Enterprise Linux, which is based on Red Hat too.
1. How to lock the account after a few (like 3) invalid password attempts?
2. How do you lock a screen after 30... (1 Reply)
Hi all,
I have to test some user priviliges. The goal is to be sure that an unauthorized user can't restart some modules (ssh, mysql etc...).
I'm trying to automate it with a shell script but in same cases I got the syslog broadcast message.
Is there any way to simply get a return code... (3 Replies)
Requirement:First i need to unlock the directory which i had a script for it.If i select app1 it should unlock the directory and after chnages in the script once need to lock the directory with lock command
The below highlighed variables in lock and unlock has to be changed according... (2 Replies)
I use Debian default encryption disk encryption. Only /boot it's not encrypted. When I boot I need to type my password, and then I will be logged in. But now I can't login. It always says that I typed the wrong password, but I typed the correct password.
I tried to boot in live-CD and try unlock... (3 Replies)
Discussion started by: zognadal
3 Replies
LEARN ABOUT DEBIAN
inn::utils::shlock
INN::Utils::Shlock(3pm) InterNetNews Documentation INN::Utils::Shlock(3pm)NAME
INN::Utils::Shlock - Wrapper around the shlock program
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 9409 2012-05-28 18:43:20Z iulius $
SEE ALSO perl(1), shlock(1).
INN 2.5.3 2012-06-15 INN::Utils::Shlock(3pm)