From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "numbchild@gmail.com" Newsgroups: gmane.emacs.help Subject: [SOLVED] Re: How to detect two emacs process in Elisp code? Date: Thu, 3 Sep 2020 10:45:09 +0800 Message-ID: References: <87ft9s283t.fsf@gmail.com> <87363z8tvl.fsf@ebih.ebihd> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10025"; mail-complaints-to="usenet@ciao.gmane.io" To: Emanuel Berg , emacs-help Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 03 04:46:02 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDfGD-0002TG-V5 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 03 Sep 2020 04:46:01 +0200 Original-Received: from localhost ([::1]:52212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDfGD-0003L9-1U for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 02 Sep 2020 22:46:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDfFs-0003L3-1l for help-gnu-emacs@gnu.org; Wed, 02 Sep 2020 22:45:40 -0400 Original-Received: from mail-ua1-x933.google.com ([2607:f8b0:4864:20::933]:37142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDfFq-00051m-0L for help-gnu-emacs@gnu.org; Wed, 02 Sep 2020 22:45:39 -0400 Original-Received: by mail-ua1-x933.google.com with SMTP id v20so398876ual.4 for ; Wed, 02 Sep 2020 19:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=0Qm2HDkLzfPSafyc9ZiAbjtZNr/Fqf3StdDFYa329ds=; b=kGqHLZALAcwZ+GyoEqbO/9w5oTv2SBxmA3cHRLThDD9nHzIOyYYePChDNJNuCuzffH L1nLKMtBCd7YLyPHVpht+d76vmJdB7UToeHDqQo+8FXrtuu0QBDQcCqlzQuT/6P4xd6d vJLA+yElSUTH/1e3dwd/kDZHagN8AjfPqHioyYSj/VBHRBtpj8kTOHHNsfqfj+pYx1xx SHr2QYmoHocgASJUKJcQbn5VPOokLoty+F1+pjHkCei2h1+l6JInkiz/faK6s3g27rLw hinMKyCXl960AK9rDen9uIybOh6h437Pe8gHkjnwg/nQXaq+HioDZvoPLJ5co6UU+KL+ z3YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=0Qm2HDkLzfPSafyc9ZiAbjtZNr/Fqf3StdDFYa329ds=; b=jyz9fUF8wDauB0KAJAJVCk6hM0UXRrnqiP43AZJTgayZkaS/5GPuNoMacrz+a7HdHX HyjTmxs2eeFN8wf73hMwPUMC7GJQ2xNFYN6iZ86BpWMd2aCwzQ/LfhtxdsOxBDS0YKUW mlknv3q5HkBfv5aUNLZiHM5NC7igGzydv8zX5RoadnvMUn7v2shsnaftJrM6g9Gzu1tf I2dh40ipgzvCmgv2ZXjrmEdPvDpChdgXTHWtyhIsstjAmLQKkO9L/gEWarkFvs40mtr3 Qck0ilPX46N4i/ctw8eg0D9IzhXkF1dfa+AISpdRkCBaRHe2aJb2VihA4AfQ+QPOZsab X9iA== X-Gm-Message-State: AOAM533G0pwEX52KNIrBCVcQXd+u5Mi4zb8oQga69l8mryJxHE9a/uHO U1WwG/MrRZ+vIChi0B+VJM+Q54eQ9kHoNFVdKHGK1Pgk0w== X-Google-Smtp-Source: ABdhPJzBAVjGbJBZyb/C+JP8TCBg882sADvcXJrPxP86dRUHOeQOdWQaAMhBszwO3SipkK08/S+Wt8pY3vLpl+BjQjA= X-Received: by 2002:ab0:60ca:: with SMTP id g10mr742593uam.109.1599101136656; Wed, 02 Sep 2020 19:45:36 -0700 (PDT) In-Reply-To: <87363z8tvl.fsf@ebih.ebihd> Received-SPF: pass client-ip=2607:f8b0:4864:20::933; envelope-from=numbchild@gmail.com; helo=mail-ua1-x933.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:123913 Archived-At: Thanks for quick reply. Confirmed it solved my problem. Thanks very much! [stardiviner] GPG key ID: 47C32433 IRC(freeenode): stardiviner Twitter: @numbchild Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 Blog: http://stardiviner.github.io/ On Thu, Sep 3, 2020 at 10:41 AM Emanuel Berg via Users list for the GNU Emacs text editor wrote: > stardiviner wrote: > > > I load desktop-save-mode session in init.el. > > But when using "bug-hunter-init-file", I need to > > exclude this session init file. > > > > Here is my try: > > > > #+begin_src emacs-lisp > > ;;; detect external system has Emacs process running? > > ;;; If yes, like `bug-hunter' is running. Then don't load session. > > ;;; FIXME > > (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))) > > #+end_src > > Try this: > > (require 'seq) > (defun how-many-emacs () > (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=") > "\n") ))))) > (message (format "Emacs process: %d" emacs-processes)) )) > ;; (how-many-emacs) ; 1 > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > >