help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to detect two emacs process in Elisp code?


From: Emanuel Berg
Subject: Re: How to detect two emacs process in Elisp code?
Date: Fri, 04 Sep 2020 06:28:27 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

stardiviner wrote:

>>>> (let ((emacs-processes
>>>>        (length (mapcar
>>>>                 'string-to-number
>>>>                 (seq-filter
>>>>                  (lambda (str)
>>>>                    (not (string-empty-p str)))
>>>>                  (split-string
>>>>                   ;; (shell-command-to-string "ps -C emacs -o pid=")
>>>>                   (shell-command-to-string "ps -C emacs -o pid=")
>>>>                   "\n"))))))
>>>>   (when (<= emacs-processes 1)
>>>>     (message "init-emacs-session loading")
>>>>     (require 'init-emacs-session)))
>>>
>>> Why do you need to use an external command ('ps')?
>>> What's wrong with using list-system-processes and
>>> process-attributes instead?
>>
>> Uhm... like this:
>>
>> (defun count-emacs ()
>>   (let ((eps 0))
>>     (cl-loop for pid in (list-system-processes)
>>              when (string= (cdar (process-attributes pid)) "emacs")
>>              do (cl-incf eps) )
>>     eps) )
>> ;; (count-emacs) ; 1
>>
>> ?
>
> This does not work perfectly, when I have Emacs
> running, then start "emacs -q" from new command.
> The upper `(list-system-processes)` solution get
> result "1" instead of "2". Maybe somewhere
> is wrong?

Yes, don't use -q :)

Fix it by replacing "emacs" above with something more
intelligent...

Or use the Unix version :)

Simpler.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

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