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: Jacob Hrbek
Subject: Re: How to capture pid of (system process?
Date: Fri, 17 Dec 2021 01:32:56 +0000

> 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. -- Tim

I don't want it to depend on an external commands as the implementation is not robust enough for my environment (this codeblock doesn't have to be robust, but the project is designed for aviation and i want to do similar implementations later for more mission critical functions).

So preferably i need a derivation that integrates with the system and is OS independent.

> If you want to do things asynchronuously, you can look at open-pipe. It should also be possible to build anything you want with the lower-level fork, execl, dup->fdes, ... primitives (assuming things are single-threaded). -- Devos

Can you elaborate? (I am noob in guile atm)

- Jacob Hrbek

On 12/14/21 14:25, Maxime Devos wrote:
Jacob Hrbek schreef op ma 13-12-2021 om 21:01 [+0000]:
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?
'system' executes the command and waits for it to complete.
After it completed, the process is dead so the pid it used to have is
useless.

If you want to do things asynchronuously, you can look at open-pipe.
It should also be possible to build anything you want with the lower-
level fork, execl, dup->fdes, ... primitives (assuming things are
single-threaded).

Greetings,
Maxime

Attachment: publickey - kreyren@rixotstudio.cz - 1677db82.asc
Description: application/pgp-keys

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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