Bash Lockfile Command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Lockfile Command
# 1  
Old 05-03-2013
Bash Lockfile Command

Hi,

I am new to this forum, could any one please help me to understand the LOCKFILE command with an example and what exactly it is used for and how it is used.

Thanks
Reshu289
# 2  
Old 05-07-2013
# 3  
Old 05-09-2013
Thanks for the reply, if you can give a small example how to use it ,that will help me a lot.
# 4  
Old 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.
# 5  
Old 05-12-2013
Thanks a lot for the update , this really helps.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run several bash commands put in bash command line?

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

2. Shell Programming and Scripting

Cp command works on command line but not in bash

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

3. UNIX for Advanced & Expert Users

Semaphore - lockfile/flock

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

4. Shell Programming and Scripting

bash: <command nm> command not found

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

5. UNIX for Advanced & Expert Users

Testing privileges -lock lockfile /var/lock/subsys/..- Permission denied

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

6. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

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

7. AIX

Typing "bash" at the command line spawns two bash processes

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

8. Shell Programming and Scripting

"lockfile: command not found"

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

9. Shell Programming and Scripting

Retry every ten seconds while lockfile present

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

10. UNIX for Dummies Questions & Answers

Bash Command

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
Login or Register to Ask a Question