in reply to Locking a script

Eeehm what I would do is to set up a temporary file with
a lock just before you enter your critical zone,
(first check if it's not there already ofcourse ;)) just unlock/unlink the file when you're done

Anyways, that's what I would do...

Replies are listed 'Best First'.
RE (tilly) 2 Locking a script
by tilly (Archbishop) on Oct 18, 2000 at 14:40 UTC
    You would have a serious race condition.

    Invocation 1 comes along, opens the file, and flocks it.

    Invocation 2 comes along, opens the file, and blocks on the flock.

    Invocation 1 leaves and unlinks the file, dropping the lock it had.

    Invocation 2 gets its lock on a temporary that only will exist until Invocation 2 is done.

    Invocation 3 comes along, sees no file, creates, flocks, and now Invocations 2 and 3 are running in parallel...

    (This is all with Unix filesystem semantics of course.)

      Okay, okay....

      Wasn't thinking heavy duty progamming for a sec. ;)))
      Dining Philosophers 'n stuff...

      How about a semaphore ?
      perldoc perlipc might give some clues...