all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: tomas@tuxteam.de
To: harven <harven@free.fr>
Cc: help-gnu-emacs@gnu.org
Subject: Re: check if another emacs instance is running
Date: Sun, 29 Nov 2009 16:12:46 +0100	[thread overview]
Message-ID: <20091129151246.GA32141@tomas> (raw)
In-Reply-To: <87pr71a5bv.fsf@ergodik.univ-brest.fr>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, Nov 29, 2009 at 01:22:28PM +0100, harven wrote:
> 
> Is there a function that checks if another instance of emacs 
> is currently running ?

Hm. What's the scope? Same user/same machine? Any user/same machine? On
the local network?

> I didn't find anything. Yet there is a command that tests if a server
> is running, and it seems to be reliable (works on all architectures, does not
> depend on the way the server was started).

At the start, the server puts a "cookie" file in a well-known place (for
the current user). The client reads this file and knows how (which
connection) to talk to the server. Besides, it can show the server that
it's allowed to.

>                                            Unfortunately I don't see how
> it can be modified so as to detect emacs instances. I tried some workarounds
> but none seems to be very satisfying.

First you have to be clear on exactly what you want (see above).

>   Use some external utility to list current processes e.g.
>   (when (< 1 (string-to-number 
>               (shell-command-to-string "ps -A |grep -c emacs23")))
>     (message "ok"))

I.e. any user in the system?

>   ;; but this is system-specific.
> 
>   Set an environment variable from emacs at start
>   ;; won't detect instances launched as emacs -Q.

Besides: this env variable will only be available to sub-shells of
Emacs...

> 
>   Open a file and see if there is a lock
>   ;; I had a look at userlock.el but did not understand how it works.

Which file?

I think mimicking the server is the best way (if you have any influence
on Emacs startup). I.e. writing a file in a well-known place. From there
you might try to take measures to catch stale files, etc.

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFLEo9uBcgs9XrR2kYRAvE2AJ9RY2fqFhYLLaRaqeuhXZhTjcsTBwCfb6dC
Qd6rLgY4ZQOc1sxJHuoCk1E=
=0p2a
-----END PGP SIGNATURE-----




  parent reply	other threads:[~2009-11-29 15:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-29 12:22 check if another emacs instance is running harven
2009-11-29 13:41 ` Juanma Barranquero
2009-11-29 15:12 ` tomas [this message]
     [not found] ` <mailman.11769.1259507965.2239.help-gnu-emacs@gnu.org>
2009-11-29 17:45   ` harven

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=20091129151246.GA32141@tomas \
    --to=tomas@tuxteam.de \
    --cc=harven@free.fr \
    --cc=help-gnu-emacs@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.