* check if another emacs instance is running
@ 2009-11-29 12:22 harven
2009-11-29 13:41 ` Juanma Barranquero
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: harven @ 2009-11-29 12:22 UTC (permalink / raw)
To: help-gnu-emacs
Is there a function that checks if another instance of emacs
is currently running ?
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). 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.
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"))
;; but this is system-specific.
Set an environment variable from emacs at start
;; won't detect instances launched as emacs -Q.
Open a file and see if there is a lock
;; I had a look at userlock.el but did not understand how it works.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: check if another emacs instance is running
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
[not found] ` <mailman.11769.1259507965.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 4+ messages in thread
From: Juanma Barranquero @ 2009-11-29 13:41 UTC (permalink / raw)
To: harven; +Cc: help-gnu-emacs
> 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"))
> ;; but this is system-specific.
On Emacs 23, you can use `list-system-processes' to obtain a list of
process PIDs, and `process-attributes' to get info for each one,
including the process name, etc.
Juanma
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: check if another emacs instance is running
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
[not found] ` <mailman.11769.1259507965.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 4+ messages in thread
From: tomas @ 2009-11-29 15:12 UTC (permalink / raw)
To: harven; +Cc: help-gnu-emacs
-----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-----
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <mailman.11769.1259507965.2239.help-gnu-emacs@gnu.org>]
* Re: check if another emacs instance is running
[not found] ` <mailman.11769.1259507965.2239.help-gnu-emacs@gnu.org>
@ 2009-11-29 17:45 ` harven
0 siblings, 0 replies; 4+ messages in thread
From: harven @ 2009-11-29 17:45 UTC (permalink / raw)
To: help-gnu-emacs
tomas@tuxteam.de writes:
> 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 am interested in same user same machine at the moment.
But if you have some hints for all users on the same machine, I would
also appreciate your advices.
>> 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.
Indeed server-socket-dir defaults to /tmp/emacs1000. I guess that's the "file"
that is tested.
>> 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?
This would test for all users, ps ux would work for the current user I think.
Depends on the OS flavor... The kind of problem I would like to avoid.
>
>> ;; 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?
Yes, that's the problem, emacs -Q does not seem to open any file
so I don't see how to check for a lock.
> 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.
Same problem as above. If some previous instance was launched with the -Q switch,
I would like to be able to detect it. Maybe it still writes something somewhere.
I think checking processes is the way to go. I will follow Juanma advice
to use list-system-processes. It only works with emacs-version 23 and above
unfortunately.
> Regards
> -- tomás
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-11-29 17:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
[not found] ` <mailman.11769.1259507965.2239.help-gnu-emacs@gnu.org>
2009-11-29 17:45 ` harven
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 read-only IMAP folder(s) and NNTP newsgroup(s).