From: Tim Van den Langenbergh <tmt_vdl@gmx.com>
To: Jacob Hrbek <kreyren@rixotstudio.cz>, guile-user@gnu.org
Subject: Re: How to capture pid of (system process?
Date: Tue, 14 Dec 2021 14:05:12 +0100 [thread overview]
Message-ID: <1f8f23a8-5210-96a5-7bb3-3b2b119c79e1@gmx.com> (raw)
In-Reply-To: <25238084-6589-146f-566c-89f7df9afad9@rixotstudio.cz>
[-- Attachment #1.1: Type: text/plain, Size: 1484 bytes --]
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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
next prev parent reply other threads:[~2021-12-14 13:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-13 21:01 How to capture pid of (system process? Jacob Hrbek
2021-12-14 13:05 ` Tim Van den Langenbergh [this message]
2021-12-14 13:25 ` Maxime Devos
2021-12-17 1:32 ` Jacob Hrbek
2021-12-17 6:45 ` Maxime Devos
2021-12-17 16:24 ` Timothy Sample
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1f8f23a8-5210-96a5-7bb3-3b2b119c79e1@gmx.com \
--to=tmt_vdl@gmx.com \
--cc=guile-user@gnu.org \
--cc=kreyren@rixotstudio.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).