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: Thu, 03 Sep 2020 19:39:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

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

?

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