guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to capture pid of (system process?


From: Tim Van den Langenbergh
Subject: Re: How to capture pid of (system process?
Date: Tue, 14 Dec 2021 14:05:12 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0

On 13/12/2021 22:01, Jacob Hrbek wrote:
> I wrote this potato-make <https://github.com/spk121/potato-make> definition 
> (was simplified):
> 
> #:SRC_BEGIN sheme-mode
> #!/usr/bin/env sh
> exec guile -s "$0" "$@"
> !#
> 
> (use-modules (ice-9 futures)
>  (potato make))
> (initialize)
> 
> (: "watch" '()
>    (~ (do ((i 1 (1+ i)))
>       ((> i 6))
>     (future (system
>      "emacs"))
>     ;;(let ((emacs_pid (getpid)))
>      ;; (kill emacs_pid SIGTERM)))))
> 
> (execute)
> #:SRC_END
> 
> expecting to capture emacs's pid and kill it, but the issue is that using 
> `getpid` gets me the PID of potato-make and `getppid` of the shell -> How can 
> i capture just the emacs's pid?
> 
> FWIW the projected end-goal is 3600 loop that checks if the `my-theme.el` 
> file has been changed to re-launch emacs with the theme loaded used for theme 
> development.
> 

Hello,

I hope this day finds you well.

While Guile does not directly provide a function to get the PID of an arbitrary 
process, we could use pgrep to find what we need.

#+begin_src scheme
  (use-modules (ice-9 popen)
               (ice-9 textual-ports))

  (map string->number
       (string-split (let ((port (open-input-pipe "pgrep emacs"))
                           (s (get-string-all port)))
                       (close-pipe port)
                       s)
                     #\newline))
  ;; => (1220 #f)
#+end_src

I hope this helps!

Vale,

-Tim

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]