Function: desktop--emacs-pid-running-p

desktop--emacs-pid-running-p is a byte-compiled function defined in desktop.el.gz.

Signature

(desktop--emacs-pid-running-p PID)

Documentation

Return non-nil if an Emacs process whose ID is PID might still be running.

Source Code

;; Defined in /usr/src/emacs/lisp/desktop.el.gz
(defun desktop--emacs-pid-running-p (pid)
  "Return non-nil if an Emacs process whose ID is PID might still be running."
  (when-let* ((attr (process-attributes pid)))
    (let ((proc-cmd (alist-get 'comm attr))
          (my-cmd (file-name-nondirectory (car command-line-args)))
          (case-fold-search t))
      (or (equal proc-cmd my-cmd)
          (and (eq system-type 'windows-nt)
               (eq t (compare-strings proc-cmd
                                      nil
                                      (if (string-suffix-p ".exe" proc-cmd t)
                                          -4)
                                      my-cmd
                                      nil
                                      (if (string-suffix-p ".exe" my-cmd t)
                                          -4))))
          ;; We should err on the safe side here: if any of the
          ;; executables is something like "emacs-nox" or "emacs-42.1"
          ;; or "gemacs", let's recognize them as well.
          (and (string-match-p "emacs" proc-cmd)
               (string-match-p "emacs" my-cmd))))))