Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

File locking within zsh?



Do any of you know of any functions, primitives, tricks, hacks, or even
outright abominations which will allow me to do cooperative file locking
from within zsh?

I know that I can do this with a number of compiled executables, but I'm
looking for a zsh-only solution.

Assuming some sort of zsh locking operator called "lock", consider
this example (within a zsh script):

  lock -x -t 0 file  # for this example of a hypothetical operator, '-x'
                     # means to wait until I get an exclusive lock, and
                     # '-t 0' means no time out
  print foo bar baz >>file
  # do a whole lot of other stuff to "file"
  unlock file # release the lock

In this example, any other zsh script which asks for an exclusive lock
on "file" using this hypothetical "lock" operator will block until the
"unlock" operator has been invoked.

Can this be done somehow in zsh, or do I have to rely on a compiled
executable to accomplish this?

Thanks in advance.

-- 
 Lloyd Zusman
 ljz@xxxxxxxxxx
 God bless you.



Messages sorted by: Reverse Date, Date, Thread, Author