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: stardiviner
Subject: Re: How to detect two emacs process in Elisp code?
Date: Fri, 04 Sep 2020 11:57:33 +0800
User-agent: mu4e 1.5.5; emacs 28.0.50

Emanuel Berg via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> writes:

> Eli Zaretskii 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?

-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3



reply via email to

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