05-09-2013
I never, but it is for IPC, for multiple processes, one probably a script, to communicate for a rendezvous -- If you get there first, wait for me. Suppose you have 5 tables in files that others can modify, that you need to read while they are stable to get an output or modify a table, like an input staging table and a target table, with supporting tables. If everyone knows they need a lockfile for any table they read or modify, it can ensure only one process uses the tables, and if modifying them, returns them to a useful state, perhaps sorted with deletions removed, before letting others use them.
It's an ugly flow! A more modern approach is to send get or modify messages in a queue to a server for each table. That server can fulfill requests for that table with no lost time.
You can find online tutorials on UNIX IPC, which is based in shared memory, which can be configured into semaphors or queues.
Many of these mechanisms can be recreated without UNIX IPC or root support using mmap(). All programs can mmap() the same file(s) and communicate through the mapped file space as shared memory, with the bonus that you can inspect the file during or after the run.
Not that lockfile does not have any halfway measures, like read only, allow read, etc. When you make the lockfile, the associated resource is yours alone until you release it by removing the lockfile. If 70 processes just want to read it, they must stand in line when they could all read at once.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
In my script I use this command \c when printing(echo) out statements but this only works in the Korn Shell(ksh).
I need the same command to be used in the Bash Shell, is there one out there?
Thanks,
the A. (1 Reply)
Discussion started by: Astudent
1 Replies
2. Shell Programming and Scripting
Hi,
I have written below check lockfile script but need some tweaking on it.
If there is a lockfile from present, I need the script to retry every 10 seconds to see if the lockfile is still there. After 120 seconds it should send an email.
In my current version, if the script encounters... (6 Replies)
Discussion started by: Meert
6 Replies
3. Shell Programming and Scripting
Just tried out the following code from "Using lockfiles in shell scripts":
#!/bin/bash
if ; then
echo "File exists"
else
echo "File does not exists. Create file now."
echo 1 > number.txt
fi
lockfile script.lock
a=$(/usr/bin/tail -n 1 number.txt)
if ; then... (1 Reply)
Discussion started by: courteous
1 Replies
4. AIX
Server: IBM p770
OS: AIX 6.1 TL5 SP1
When one of our develoeprs types "bash" on the command line to switch shells, it hangs. For some reason, two bash processes are created....the first bash process spawns a second bash process in the same console, causing a hang. Anyone have any idea what... (2 Replies)
Discussion started by: wjssj
2 Replies
5. UNIX for Dummies Questions & Answers
I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing
set
you can also use them "on the command line when running a script..." and it lists this in a small table:
set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies
6. 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
7. Shell Programming and Scripting
I created a script that I need to run from time to time, but get this error message. To get it working again I run this command from time to time:
export PATH="$PATH:~/scripts"
I put all my automated scripts in the /scripts directory and would like to run my scripts from any directory... (5 Replies)
Discussion started by: catalinawinemxr
5 Replies
8. UNIX for Advanced & Expert Users
Hi,
I have a process which can run one instance at a time. Currently we have multiple scripts trying to kickoff this process. I wanted to implement the semaphore mechanism to achieve this.
I was going through few examples. The below code seems to be reasonable solution.
... (5 Replies)
Discussion started by: tostay2003
5 Replies
9. Shell Programming and Scripting
The below command moves all the .vcf files into the directory.
cp /home/cmccabe/Desktop/test/vcf/overall/stats/*.vcf /home/cmccabe/Desktop/NGS/annovar
When I use a bash wrapper the target.txt gets created but the text files do not get copied. All the paths are the same, but not sure why... (2 Replies)
Discussion started by: cmccabe
2 Replies
10. Shell Programming and Scripting
How to run several bash commands put in bash command line without needing and requiring a script file.
Because I'm actually a windows guy and new here so for illustration is sort of :
$ bash "echo ${PATH} & echo have a nice day!"
will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies
LEARN ABOUT CENTOS
dotlockfile
DOTLOCKFILE(1) Cistron Utilities DOTLOCKFILE(1)
NAME
dotlockfile - Utility to manage lockfiles
SYNOPSIS
/usr/bin/dotlockfile [-p] [-c] [-m] [-l|-u|-t] [-r retries] [lockfile]
DESCRIPTION
Dotlockfile is a command line utility to safely create, test and remove lockfiles. Lockfiles are created in an NFS-safe way. Dotlockfile
can can also be used to lock and unlock mailboxes even if the mailspool directory is only writable by group mail.
The name dotlockfile comes from the way mailboxes are locked for updates on a lot of UNIX systems. A lockfile is created with the same
filename as the mailbox but with the string ".lock" appended.
The names dotlock and lockfile were already taken - hence the name dotlockfile :).
OPTIONS
-l Create a lockfile. This is the default.
-u Remove a lockfile.
-c Check for the existence of a valid lockfile.
-t Touch an existing lockfile (update the timestamp).
-p Write the process-id of the calling process into the lockfile. Also when testing for an existing lockfile, check the contents for a
process-id to find out if the lockfile is still valid.
-r retries
The number of times dotlockfile retries to acquire the lock if it failed the first time before giving up. The initial sleep after
failing to acquire the lock is 5 seconds. After each next try, a sleep of 5 seconds extra occurs up to a maximum sleep of 60 seconds
between tries. The default number of retries is 5.
-m Lock or unlock the current users mailbox. The path to the mailbox is the default system mailspool directory (usually /var/mail) with
the username as gotten from getpwuid() appended. If the environment variable $MAIL is set, that is used instead. Then the string
".lock" is appended to get the name of the actual lockfile.
lockfile
The lockfile to be created/removed, unless the -m option is in effect.
RETURN VALUE
Zero on success, and non-zero on failure. For the -c option, sucess means that a valid lockfile is already present. When locking (the
default, or the -l option) dotlockfile returns the same values as the library function lockfile_create(3). Unlocking a non-existant lock-
file is not an error.
NOTES
The lockfile is created exactly as named on the command line. The extension .lock is not automatically added.
This utility is a lot like the lockfile(1) utility included with procmail, and the mutt_dotlock(1) utility included with mutt. However the
command-line arguments differ, and so does the return status. It is believed that dotlockfile is the most flexible implementation, since it
automatically detects when it needs to use priviliges to lock a mailbox, and does it safely.
The above mentioned lockfile_create(3) manpage is present in the liblockfile-dev package.
BUGS
None known.
SEE ALSO
lockfile_create(3), maillock(3)
AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl
15 May 2003 DOTLOCKFILE(1)