[mythtv-users] stagger start times for simultaneous recordings?

Mike Holden mythtv at mikeholden.org
Sun Oct 23 10:21:03 UTC 2011


Ronald Frazier wrote:
>> Were it me, I'd try and implement some crude form of "locking"
>> inside the channel-change script(s), so that one instance would
>> loop and sleep/wait until the other has finished its thing.
>
> A while back I had a channel change script with some very basic
> locking code in it. It doesn't handle race conditions, but should
> work
> pretty good (might fail once in a million times or something).
> Here's
> a copy:
>
> while [ -f $LOCKFILE ]
> do
> #echo "Waiting for lock..."
>   sleep .1
> done
>
> touch $LOCKFILE

I suggest you have a look at "flock" (man flock has a good simple
overview). This provides a simple but foolproof locking mechanism
using a file locked in exclusive mode.

(
    flock -s 200
    # ... commands executed under lock ...
) 200>/path/to/mylockfile

-- 
Mike Holden




More information about the mythtv-users mailing list