Re: Concurrent Updates of the Same File by 2 Instances of the Same Shell Script
- From: Pascal Bourguignon <usenet@xxxxxxxxxxxxxxxxx>
- Date: Thu, 16 Feb 2006 20:50:45 +0100
"John Smith" <wleung7@xxxxxxxxx> writes:
Chris wrote:
Some possibilities:
--Use the presence of another file in the filesystem as a lock.
if i use a lockfile, i can only restrict access to the file by
terminating the S2. How do I make S2 "busy-wait" for S1 to finish such
that S1 and S2 are serialized?
This is done automatically by the lock syscall.
From the shell, you'd use a tool that'd call it.
For example, on unix you can use flock(1):
#!/bin/bash
file=/tmp/example
line="Random line ${RANDOM}"
flock "${file}" bash -c "echo \"${line}\" >> \"${file}\""
You can also try:
flock --timeout=60 "${file}" \
bash -c "sleep 10;echo \"waiter ${RANDOM}\">>\"${file}\"" &
flock --timeout=60 "${file}" \
bash -c "echo \"quicker ${RANDOM}\" >> \"${file}\""
--
__Pascal Bourguignon__ http://www.informatimago.com/
NEW GRAND UNIFIED THEORY DISCLAIMER: The manufacturer may
technically be entitled to claim that this product is
ten-dimensional. However, the consumer is reminded that this
confers no legal rights above and beyond those applicable to
three-dimensional objects, since the seven new dimensions are
"rolled up" into such a small "area" that they cannot be
detected.
.
- Follow-Ups:
- References:
- Prev by Date: Re: Concurrent Updates of the Same File by 2 Instances of the Same Shell Script
- Next by Date: Re: Concurrent Updates of the Same File by 2 Instances of the Same Shell Script
- Previous by thread: Re: Concurrent Updates of the Same File by 2 Instances of the Same Shell Script
- Next by thread: Re: Concurrent Updates of the Same File by 2 Instances of the Same Shell Script
- Index(es):
Relevant Pages
|