Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: File locking within zsh?
- X-seq: zsh-users 10242
- From: Tim Writer <tim@xxxxxxxxxxx>
- To: Lloyd Zusman <ljz@xxxxxxxxxx>
- Subject: Re: File locking within zsh?
- Date: 10 May 2006 18:04:18 -0400
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <877j4ujizh.fsf@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <87r7324zyh.fsf@xxxxxxxxxx> <ltd5emv9lh.fsf@xxxxxxxxxxxxxxxxxx> <009101c673f7$06b3f090$6500000a@venti> <877j4ujizh.fsf@xxxxxxxxxx>
- Sender: tim@xxxxxxxxxxx
Lloyd Zusman <ljz@xxxxxxxxxx> writes:
> "Brian K. White" <brian@xxxxxxxxx> writes:
>
> > From: "Tim Writer" <tim@xxxxxxxxxxx>
> >
> >> [ ... ]
> >>
> >> while ! ln file file.lock 2>/dev/null
> >> do
> >> sleep 1
> >> done
> >> # Lock obtained
> >>
> >> print foo bar baz >>file
> >> # do a whole lot of other stuff to "file"
> >>
> >> rm -f file.lock
> >> # Lock released
> >>
> >> Wrapping this idiom into lock/unlock functions is left as an exercise
> >> for the
> >> reader. :-)
> >
> >
> > Is that better or worse, and why, than umask 222 ; >file ?
> >
> > http://www.unix.org.ua/orelly/unix/upt/ch45_36.htm
>
> Thanks to both of you (Brian K. White and Tim Writer). I personally
> like the umask version better, because I think I can implement a
> variation of it without spawning any extra processes (my goal), given
> that umask is an internal zsh command.
Keep in mind that you have to put umask in a subshell, like this:
( umask 222; >file )
in order to preserve it. IIRC, zsh avoids forking in subshells but don't most
shells implement subshells with fork()?
Keep in mind that ln is a tiny wrapper around the link(2) system call and so
there's only a very small amount of overhead in running it. With zsh, you
can have your cake and eat it too using the zsh/files which makes ln a
builtin (among other things).
--
tim writer <tim@xxxxxxxxxxx> starnix inc.
647.722.5301 toronto, ontario, canada
http://www.starnix.com professional linux services & products
Messages sorted by:
Reverse Date,
Date,
Thread,
Author