-   Programming (
-   -   Bash question (

lnxduck 09-30-2005 06:54 AM

Bash question
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

acid_kewpie 09-30-2005 07:31 AM

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.

lnxduck 09-30-2005 07:35 AM

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...

jlliagre 09-30-2005 08:50 AM

Look here for a possible solution:

All times are GMT -5. The time now is 11:36 AM.