[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GNU Shepherd 0.10.3 released
|
From: |
Ludovic Courtès |
|
Subject: |
Re: GNU Shepherd 0.10.3 released |
|
Date: |
Mon, 29 Jan 2024 17:31:33 +0100 |
|
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Hi,
Tomas Volf <~@wolfsden.cz> skribis:
> Ah, that code indeed returns #f for the pid in question:
>
> scheme@(guix-user)> ((@@ (guix build syscalls) kernel?) 688)
> $1 = #f
>
> The stat file:
>
> $ cat /proc/688/stat
> 688 (mt76-tx phy0) S 2 0 0 0 -1 2129984 0 0 0 0 0 0 0 0 -2 0 1 0 964 0 0
> 18446744073709551615 0 0 0 0 0 0 0 2147483647 0 0 0 0 17 5 1 1 0 0 0 0 0 0 0
> 0 0 0 0
>
> So the start_code is not zero (I would guess it is -1). I have no idea what
> that means though.
What about this method (from shepherd)?
--8<---------------cut here---------------start------------->8---
(define (linux-process-flags pid)
"Return the process flags of @var{pid} (or'd @code{PF_} constants), assuming
the Linux /proc file system is mounted; raise a @code{system-error} exception
otherwise."
(call-with-input-file (string-append "/proc/" (number->string pid)
"/stat")
(lambda (port)
(define line
(get-string-all port))
;; Parse like systemd's 'is_kernel_thread' function.
(let ((offset (string-index line #\)))) ;offset past 'tcomm' field
(match (and offset
(string-tokenize (string-drop line (+ offset 1))))
((state ppid pgrp sid tty-nr tty-pgrp flags . _)
(or (string->number flags) 0))
(_
0))))))
;; Per-process flag defined in <linux/sched.h>.
(define PF_KTHREAD #x00200000) ;I am a kernel thread
(define (linux-kernel-thread? pid)
"Return true if @var{pid} is a Linux kernel thread."
(= PF_KTHREAD (logand (linux-process-flags pid) PF_KTHREAD)))
--8<---------------cut here---------------end--------------->8---
If it works better, we can use that in syscalls.scm as well.
Ludo’.
PS: Having an entry in bug-guix would ensure we don’t lose track of this.
Re: GNU Shepherd 0.10.3 released, Wilko Meyer, 2024/01/07