On Sun, Jan 30, 2000 at 02:21:25PM +0100, Gustav Schaffter wrote:
| SoloCDM wrote:
| > How do I issue a command that will prevent two possible executed
| > instances of the same program?
| 
| Short answer: You can't. (At least AFAIK :-)
| Long answer: You can. Almost.
| You may create a shell script (I believe) or a Perl script (I know) that
| will use flock to verify that it is running in one instance only. [...]

Flock doesn't always work over nfs. And there isn't always a handy
file to put a lock on anyway, depending.

But yes, you want a wrapper which uses an agreed-upon convention.
Then you never invoke the program directly, just the wrapper.

I do this for my mutt invocations, here's the wrapper:

    #!/bin/sh
    #
    # Shortcut to threaded mailbox.
    #   - Cameron Simpson <[EMAIL PROTECTED]> 11oct99
    #

    box=`basename "$0"`
    exec term -n "mutt $box" -e pushttylabel "mutt $box" lock "mail/$box" mutt -f 
"$box"

Let's look at that one:

        - this script is linked to the names "+attn", "+linux-misc", etc so
          to read particular mailboxes I just type the command "+attn" etc

        - "term" is just a script to open a new window (or not, if X
          isn't active)

        - "lock" is the core locking tool
                its first argument is the name for the lock, "mail/+attn"
                    in this case if I'd typed "+attn"
                its remaining arguments are a command to run once the lock
                    is obtained
                it takes a few other options, like "-1" to say "if the lock's
                taken don't bother running the command at all" which is handy
                to ensure some service it up without starting multiple copies

So this script opens a new window, obtains a lock on the mailbox and
then runs mutt.

You can obtain lock from
        http://www.zip.com.au/~cs/scripts/lock
You will want a lock directory; in the absense of other config it uses
        $HOME/.locks

It requires my perl modules, from here:
        http://www.zip.com.au/~cs/cs.tar.gz

There's a (quite) little writeup at:
        http://www.zip.com.au/~cs/#scripts

Cheers,
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

When I grow up I want to be an idiot savant.  I'm already halfway there...
        - Kenneth, [EMAIL PROTECTED]


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to