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: Sat, 18 Jul 2020 22:01:21 +0800 Message-ID: References: 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="14422"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-help To: Noam Postavsky Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 18 16:02:19 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 1jwnPu-0003fs-Nj for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 18 Jul 2020 16:02:18 +0200 Original-Received: from localhost ([::1]:46704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwnPt-0004ti-Fg for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 18 Jul 2020 10:02:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwnPT-0004tY-Kd for help-gnu-emacs@gnu.org; Sat, 18 Jul 2020 10:01:51 -0400 Original-Received: from mail-vk1-xa33.google.com ([2607:f8b0:4864:20::a33]:43304) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jwnPR-0000Cz-0R for help-gnu-emacs@gnu.org; Sat, 18 Jul 2020 10:01:51 -0400 Original-Received: by mail-vk1-xa33.google.com with SMTP id e10so2728860vkm.10 for ; Sat, 18 Jul 2020 07:01:48 -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 :cc; bh=h+cRJ+vczdQayisvYSpdJv9fQ1IcJ0R+udcI+6XoT20=; b=fDM9WwOjmmZNc7jCiqiMglpkEGV/vUJTNdTcYckXJzEEdmfDs3P8jd3gx/HxzG16zZ 9f4JVVeqAtE08ZNsEGSAWRMVO2ScTcMrOUyfirQ7SJI59jDB56uY2fs+lHZnAS7ub09d Wffziu3EXnl3q/usGYqKl8Dl1WA7qUZBTbQV/+uHlXJaAm2mLLd5WI2zA/0JK2IQdvjB AyHuTQkiO2dnTISKaa9T0AyGCerj+xRgWyRHO5UTrscoDFyAg/sL9ZF87TcCHdWku1RO ytFLEfEbJGPwfR7h2e5Sm8GPsatLFJNt8gisxW1B+Yqxs9sAiscr9kNHf1zOfnnCpYYO OBfA== 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:cc; bh=h+cRJ+vczdQayisvYSpdJv9fQ1IcJ0R+udcI+6XoT20=; b=AfZkPNWO8ynSrUN3eMrtE5VglrTiHRWRqkS1tbdIUD8+jTPEswBd7X143wKvnFQAFg wKIOwBdr2CrDzeFNKc5r5b5TvEUpeaSSBKxES2EYoiHlpe4ogCTnj+bXReakdEF/birE 0qFc3VwkiYMHCDeGLI7WV1ZG+qjCJvvZmc8Qoh5Q64eAjoInUZnrbIO7iwfLbc5KfaEy As0OCN17d8Oz4Gmm8j4scc9z347j1BQylsUCsKB+hgafTs1l0TfumSGAXFiAYcEoiPev kyg11zCmd8ln5KjUBDDC7ePoPNoh1vT//Ff98oWqrAvY0LqFDoYXEnYRkNqUFbld9zxm fajA== X-Gm-Message-State: AOAM531oSnNVCe5PVOS10pH5ioCrEyfFbowa35n3B6XGs2Zwh786f3L7 IYQzYl8mCcU5L5OoDCHMhYWL1p8cIpGRsaj0Ug== X-Google-Smtp-Source: ABdhPJx87FUoDiouXVtVR0jtfXp6wR5CjkRbhKiWVvv2WNvkmoDxcJ3fXqo57z8ju7bnb+SGTq/ak9eR0GK6AriiXVs= X-Received: by 2002:a05:6122:128e:: with SMTP id i14mr9610041vkp.20.1595080907913; Sat, 18 Jul 2020 07:01:47 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::a33; envelope-from=numbchild@gmail.com; helo=mail-vk1-xa33.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:123557 Archived-At: Really thanks, Noam. You're awesome! This solved my problem. [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 Sat, Jul 18, 2020 at 8:25 PM Noam Postavsky wrote: > On Sat, 18 Jul 2020 at 01:56, 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 "\\" (alist-get 'comm proc)))) > (mapcar #'process-attributes (list-system-processes))) >