From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: stardiviner Newsgroups: gmane.emacs.help Subject: Re: How to detect two emacs process in Elisp code? Date: Fri, 04 Sep 2020 11:57:33 +0800 Message-ID: <5f51bece.1c69fb81.e6e79.9840@mx.google.com> References: <87ft9s283t.fsf@gmail.com> <83lfhruhnz.fsf@gnu.org> <87pn72bvzt.fsf@ebih.ebihd> Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3636"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.5; emacs 28.0.50 Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 04 06:13:28 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 1kE36O-0000of-MT for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 04 Sep 2020 06:13:28 +0200 Original-Received: from localhost ([::1]:50808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kE36N-00024k-Nv for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 04 Sep 2020 00:13:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kE363-00024W-MZ for help-gnu-emacs@gnu.org; Fri, 04 Sep 2020 00:13:07 -0400 Original-Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:44551) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kE361-0007qw-L3 for help-gnu-emacs@gnu.org; Fri, 04 Sep 2020 00:13:07 -0400 Original-Received: by mail-pl1-x62e.google.com with SMTP id q3so532748pls.11 for ; Thu, 03 Sep 2020 21:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:references:user-agent:from:to:cc:subject:reply-to :in-reply-to:date:mime-version; bh=J0hLoefNapegfflH1PG3FQhaW61lp9hQHfQCF+CvfrI=; b=E2+jIdzUbgdBjX6f+CesjDpairBh6GdzvUBCKloFLfcF2o18YrfqXv3445kWMd2KX2 z4AZVQEb0RXe5ShL+BxTSzHv2piRazpq6x2+RHqeeJALB+VJuGR5hJt+l5qxcT077Pla +CG2VEGcIr1h8B9iYkPhjqWQ+d8BsL4VF3aDbhXXW+BXdNiCx70LetK38is3Jw/y9t9U wJuJahNwL7T+5bRESCNUxTZkwqltYQ/wCHns4aIAnv2dupr1Efi5aWXxGzbczw9Qd2jx QewnkMvzzXrNz85yZyapYDVKgpqowXAc3G5DlmAxQVy9vRpE+tcCnNsc/iUg+dEJ0klO H4Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:references:user-agent:from:to:cc :subject:reply-to:in-reply-to:date:mime-version; bh=J0hLoefNapegfflH1PG3FQhaW61lp9hQHfQCF+CvfrI=; b=cs5WpOrvEBU6LUNl7lCUn94W8tNyrR3htpLeEPTGQv1e0ypKvl34YZ08Q8QCUnbxlo 2ZxHBsNNmYIK1tkcTqgb/JStAeogfdVUK10zeKJdKrVB/sVV1v1m9vwKyOB2P6BHQahz DIw4EzA28miuc5EsS/qHyuvgL7hBi++2uKqOXDlEfMm0pbbkP4ed31FF1zmTB61xltQ9 MKXbyZzElG6DccEN2A8M64dP9vI86bI5tc4JXCiw0LFPYuSMilw+2TSwB7zbNlAHNsh/ XnA62V4QdFaDXjldqjQu9JYvHPK7h6B1/Kn58diqoi0AcVaAmgwXGk2imoSj9A2Oc5Xg r6kg== X-Gm-Message-State: AOAM530GOz5VKe4L+An72PCMjB4wN/d/Lc9+EJiyhZSEuMtr+vbYIvUp KRrQxo4FHGs+O4Bx9EZJG1FyFaQPnneQ X-Google-Smtp-Source: ABdhPJxjDbwPEc3PQXud0xXC57rRTAdfQP/WsSaowC+S4jztf4YK+3UfSnqTo4z4XVJHqvBsZg4RQw== X-Received: by 2002:a17:90a:aa8e:: with SMTP id l14mr6645319pjq.67.1599192783456; Thu, 03 Sep 2020 21:13:03 -0700 (PDT) Original-Received: from dark.gmail.com ([183.246.146.178]) by smtp.gmail.com with ESMTPSA id jz6sm3905800pjb.22.2020.09.03.21.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 21:13:02 -0700 (PDT) X-Google-Original-Message-ID: <87imcuyz0y.fsf@numbchild@gmail.com> In-reply-to: <87pn72bvzt.fsf@ebih.ebihd> Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=numbchild@gmail.com; helo=mail-pl1-x62e.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, 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-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:123950 Archived-At: Emanuel Berg via Users list for the GNU Emacs text editor 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