Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: File locking within zsh?
- X-seq: zsh-users 10240
- From: DervishD <zsh@xxxxxxxxxxxx>
- To: Lloyd Zusman <ljz@xxxxxxxxxx>
- Subject: Re: File locking within zsh?
- Date: Wed, 10 May 2006 23:21:55 +0200
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <87y7xai4ev.fsf@xxxxxxxxxx>
- Mail-followup-to: Lloyd Zusman <ljz@xxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: DervishD
- References: <87r7324zyh.fsf@xxxxxxxxxx> <20060510062930.GB4340@DervishD> <87y7xai4ev.fsf@xxxxxxxxxx>
Hola Lloyd :)))
* Lloyd Zusman <ljz@xxxxxxxxxx> dixit:
> >> 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.
>
> Well, the perl interpreter is a compiled executable, and a rather
> heavy one, at that. I'm trying to avoid spawning any extra
> processes.
OK. I thought that your problem was that you didn't want to write
it in C, for example. If you're trying to avoid heavy binaries, avoid
Perl ;))
> > If you could ellaborate on the problem you're trying to solve, I
> > can try to give a better solution.
>
> I'm writing a zsh shell function that might be invoked within concurrent
> terminal sessions. There's a critical section of code within this shell
> function that I want to protect with an exclusive lock. I only need to
> protect this critical section from other invocations of this same shell
> function.
OK, then probably the 'ln' solution will do.
> Perhaps I can write a loadable zsh module which can supply this
> capability.
Probably, but that's a lot of work for something you can achieve
using 'ln'. You can even write a couple of shell functions using 'ln'
to do the locking.
The only problem I see with the 'ln' solution is that it doesn't
block, you're forced to use a busy-wait loop :((
If you don't want to use a busy-wait loop, you can try to use a
FIFO (in the filesystem, I mean) or a socket. Synchronizing more than
two tasks using those mechanism is tricky, but I think it can be
done. Think of your problem not as a "locking problem" but just as an
"IPC problem". A bit complex, anyway, because the shell doesn't
provide atomic operations that block (AFAIK).
Of course, a zsh module for doing locking would be great ;) (or
adding the needed functions to zsh/files, for example).
> > Good luck :)
>
> Muchas gracias. :)
De nada :))) I'm happy of reading you again :)
BTW, this issue has been partially addressed in zsh-users 8632
and 8633.
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