02-18-06 03:40 AM
"John Smith" <wleung7@gmail.com> 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.
[ Post a follow-up to this message ]
|