05-28-2014
There's also a "flock" command (as opposed to the library routine of the same name) available which may be pre-installed or at least pre-packaged on the systems you care about. It does exactly what you'd expect... If you need to pull the source the man page says this:
The flock command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
So you don't need to write your own unless you want to.
---------- Post updated at 14:23 ---------- Previous update was at 14:19 ----------
And to answer the question in your script comments, if you use lock files, you don't need to bother cleaning up since when the process dies the lock is released. But if you do code something using semaphores instead, you will need to make sure to clean up since they aren't link to the existence of a given process and clear on their own.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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)
Discussion started by: dianayun
7 Replies
2. Solaris
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)
Discussion started by: smartboy1461
1 Replies
3. Solaris
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)
Discussion started by: dwarf007
1 Replies
4. HP-UX
Hi,
not able to unlock user eventhough executed /usr/lbin/modprpw -k username
Thanks in advance (2 Replies)
Discussion started by: bpsunadm
2 Replies
5. AIX
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)
Discussion started by: rainbow_bean
2 Replies
6. UNIX for Dummies Questions & Answers
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)
Discussion started by: sbarnes
1 Replies
7. Red Hat
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)
Discussion started by: nstarz
1 Replies
8. UNIX for Advanced & Expert Users
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)
Discussion started by: Dedalus
3 Replies
9. Shell Programming and Scripting
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)
Discussion started by: bhas85
2 Replies
10. UNIX for Beginners Questions & Answers
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 XFREE86
lslocks
LSLOCKS(8) System Administration LSLOCKS(8)
NAME
lslocks - list local system locks
SYNOPSIS
lslocks [options]
DESCRIPTION
lslocks lists information about all the currently held file locks in a Linux system.
OPTIONS
-i, --noinaccessible
Ignore lock files which are inaccessible for the current user.
-J, --json
Use JSON output format.
-n, --noheadings
Do not print a header line.
-o, --output list
Specify which output columns to print. Use --help to get a list of all supported columns.
The default list of columns may be extended if list is specified in the format +list (e.g. lslocks -o +BLOCKER).
-p, --pid pid
Display only the locks held by the process with this pid.
-r, --raw
Use the raw output format.
-u, --notruncate
Do not truncate text in columns.
-V, --version
Display version information and exit.
-h, --help
Display help text and exit.
OUTPUT
COMMAND
The command name of the process holding the lock.
PID The process ID of the process which holds the lock.
TYPE The type of lock; can be FLOCK (created with flock(2)), POSIX (created with fcntl(2) and lockf(3)) or OFDLCK (created with fcntl(2).
SIZE Size of the locked file.
MODE The lock's access permissions (read, write). If the process is blocked and waiting for the lock, then the mode is postfixed with an
'*' (asterisk).
M Whether the lock is mandatory; 0 means no (meaning the lock is only advisory), 1 means yes. (See fcntl(2).)
START Relative byte offset of the lock.
END Ending offset of the lock.
PATH Full path of the lock. If none is found, or there are no permissions to read the path, it will fall back to the device's mountpoint
and "..." is appended to the path. The path might be truncated; use --notruncate to get the full path.
BLOCKER
The PID of the process which blocks the lock.
NOTES
The lslocks command is meant to replace the lslk(8) command,
originally written by Victor A. Abell <abe@purdue.edu> and unmaintained
since 2001.
AUTHORS
Davidlohr Bueso <dave@gnu.org>
SEE ALSO
flock(1), fcntl(2), lockf(3)
AVAILABILITY
The lslocks command is part of the util-linux package and is available from https://www.kernel.org/pub/linux/utils/util-linux/.
util-linux December 2014 LSLOCKS(8)