[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: check if another emacs instance is running

From: tomas
Subject: Re: check if another emacs instance is running
Date: Sun, 29 Nov 2009 16:12:46 +0100
User-agent: Mutt/1.5.15+20070412 (2007-04-11)

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

>   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.

- -- tomás
Version: GnuPG v1.4.6 (GNU/Linux)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]