LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-30-2005, 06:54 AM   #1
lnxduck
LQ Newbie
 
Registered: Sep 2005
Posts: 2

Rep: Reputation: 0
Bash question


Hi,
I am new to bash, and need to use flock or something similar
in order to lock a file. How can I do this from bash?

I need to lock a file, block until its locked and if my bash process dies - release the lock automatically. If I use another process to do the locking,
the release part is easy, but I'll need to somehow block in the bash script until that process gets the lock. I'm not sure how to do this and if this is the simplest way to achieve what i need.

Thank you
 
Old 09-30-2005, 07:31 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,374

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
most standard bash level locking is simply done with the existnace or not of flag files, e.g. /tmp/myscript.lock just touch it to create it and clear up correctly.
 
Old 09-30-2005, 07:35 AM   #3
lnxduck
LQ Newbie
 
Registered: Sep 2005
Posts: 2

Original Poster
Rep: Reputation: 0
thanks. The problem with this is that if the process that took the lock
get killed, the file stays and everybody else stay blocked. This problem can be solved by flock / fcntl in C or Perl. The lock is there until the process unlocks it or dies. I am looking for a bash alternative...
 
Old 09-30-2005, 08:50 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,481

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Look here for a possible solution:
http://members.toast.net/art.ross/rute/node24.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A question about BASH operand Linux - Newbie 2 11-27-2005 09:49 PM
BASH question robscott Linux - Software 3 11-23-2005 09:39 AM
bash question? shanenin Linux - Software 1 11-26-2004 12:22 PM
BASH question tpe Linux - Software 6 11-17-2004 08:59 PM
little bash question gplacek Linux - General 2 09-01-2004 12:10 PM


All times are GMT -5. The time now is 04:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration