2

I would like to check if my shell is running ssh or not by checking the process name. I tried to get the process name by:

(let* ((proc (get-process "shell")) (proc-child-id (process-running-child-p proc)))
  (if proc-child-id
     (message (process-name proc-child-id))))

But it doesn't work because process-name expect a PROCESS instead of PID. How can I get PROCESS from PID? Or how can I get the child process name directly?

7
  • 2
    Try to check if (alist-get 'comm (process-attributes PID)) returns ssh. BTW, the ssh process is created by shell, not Emacs, so it is not an Emacs subprocess so process-name etc doesn't make sense, I guess. See gnu.org/software/emacs/manual/html_node/elisp/…
    – xuchunyang
    Apr 3, 2018 at 17:28
  • Somehow it always returns nil.. Thanks for your reply anyway~
    – AhLeung
    Apr 4, 2018 at 2:57
  • This is my guess: "In some environments, process-attributes is unimplimented and always returns nil." notmuchmail.org/pipermail/notmuch/2014/016796.html I'm using Emacs.app from emacsformacosx.com
    – AhLeung
    Apr 4, 2018 at 3:15
  • 1
    If so, you can try ps -o comm= -p PID. process-attributes doesn't return nil from here, I am using latest Emacs (built from git repo last month) on Mac.
    – xuchunyang
    Apr 4, 2018 at 4:15
  • 1
    shell-command returns exit status. shell-command-to-string returns the output.
    – xuchunyang
    Apr 4, 2018 at 5:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.