zsh-users
 help / color / mirror / code / Atom feed
From: Tim Writer <tim@starnix.com>
To: Lloyd Zusman <ljz@asfast.com>
Cc: zsh-users@sunsite.dk
Subject: Re: File locking within zsh?
Date: 10 May 2006 18:04:18 -0400	[thread overview]
Message-ID: <ltejz1sfj1.fsf@newsol.starnix.com> (raw)
In-Reply-To: <877j4ujizh.fsf@asfast.com>

Lloyd Zusman <ljz@asfast.com> writes:

> "Brian K. White" <brian@aljex.com> writes:
> 
> > From: "Tim Writer" <tim@starnix.com>
> >
> >> [ ... ]
> >>
> >>    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@starnix.com>                                  starnix inc.
647.722.5301                                      toronto, ontario, canada
http://www.starnix.com              professional linux services & products


  reply	other threads:[~2006-05-10 21:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-09 22:04 Lloyd Zusman
2006-05-10  3:31 ` Tim Writer
2006-05-10  5:59   ` Brian K. White
2006-05-10 10:02     ` Lloyd Zusman
2006-05-10 22:04       ` Tim Writer [this message]
2006-05-11  3:41         ` Bart Schaefer
2006-05-11 14:25           ` Tim Writer
2006-05-11 15:01             ` Peter Stephenson
2006-05-12  4:22               ` Tim Writer
2006-05-12  9:17               ` Subshells and parameters (was: File locking within zsh?) Vincent Lefevre
2006-05-12 12:09                 ` Subshells and parameters Lloyd Zusman
2006-05-12 23:09                   ` Vincent Lefevre
2006-05-13  2:05                     ` Lloyd Zusman
2006-05-17 14:24                       ` Vincent Lefevre
2006-05-17 15:42                         ` Bart Schaefer
2006-05-17 16:07                           ` Vincent Lefevre
2006-05-13  2:10                     ` Dan Nelson
2006-05-11 16:13             ` File locking within zsh? Brian K. White
2006-05-10 17:13     ` Vincent Lefevre
2006-05-11 15:45       ` Brian K. White
2006-05-12  7:54         ` Vincent Lefevre
2006-05-12 19:40           ` Tim Writer
2006-05-12 23:24             ` Vincent Lefevre
2006-05-10 21:53     ` Tim Writer
2006-05-10  6:29 ` DervishD
2006-05-10 10:02   ` Lloyd Zusman
2006-05-10 21:21     ` DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ltejz1sfj1.fsf@newsol.starnix.com \
    --to=tim@starnix.com \
    --cc=ljz@asfast.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).