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

Re: File locking within zsh?



    Hi Lloyd :)

 * Lloyd Zusman <ljz@xxxxxxxxxx> dixit:
> 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.

    Apart from the 'ln' trick, you can do this in Perl if you don't
want compiled executables. This way you can embed the locking into
your zsh script without the need of having separate scripts or
compiled executables, using "perl -e".

    Unless you need real file locking (because you have to cooperate
with another external binary), you should use the 'ln' trick instead
of using locks.

    Which solution to use depends utterly on which problem are you
trying to solve. If your problem is that you have to write
exclusively to a file, and that file may have been "lockf()"ed by
another program, then you need real lock semantics and that may be a
problem to do from zsh. I would switch to Perl or something similar
to do the task (or a zsh+Perl mix, for example). If, on the other
hand, you just need to make sure that all instances of your script
won't write to the same file at the same time, go ahead with the 'ln'
solution.

    If you could ellaborate on the problem you're trying to solve, I
can try to give a better solution.

    Good luck :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to... RAmen!



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