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: Noam Postavsky
Subject: Re: How to detect two emacs process in Elisp code?
Date: Sat, 18 Jul 2020 08:25:23 -0400

On Sat, 18 Jul 2020 at 01:56, numbchild@gmail.com <numbchild@gmail.com> wrote:

>                   (shell-command-to-string "ps -C emacs -o pid=")
>                   "\n"))))))
>   (when (<= emacs-processes 1)
>     (message "init-emacs-session loading")
>     (require 'init-emacs-session)))
> #+end_src
>
> The upper code has a problem, the command "ps -C emacs -o pid=" can't detect
> emacs program name like "emacs-28.2.3" which is in /usr/local/bin and
> compiled from source code.

If your init does (server-start), then you can just check for
(server-running-p). Otherwise, something like

(seq-count
 (lambda (proc) (and (equal (alist-get 'user proc) user-login-name)
                (string-match "\\<emacs\\>" (alist-get 'comm proc))))
 (mapcar #'process-attributes (list-system-processes)))



reply via email to

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