syscalls: Add 'processes' to list all the live processes.
* guix/build/syscalls.scm (kernel?, processes): New procedures.
This commit is contained in:
parent
211345b3a5
commit
17a4d34489
|
@ -22,13 +22,15 @@
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (ice-9 rdelim)
|
#:use-module (ice-9 rdelim)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
|
#:use-module (ice-9 ftw)
|
||||||
#:export (errno
|
#:export (errno
|
||||||
MS_RDONLY
|
MS_RDONLY
|
||||||
MS_REMOUNT
|
MS_REMOUNT
|
||||||
MS_BIND
|
MS_BIND
|
||||||
MS_MOVE
|
MS_MOVE
|
||||||
mount
|
mount
|
||||||
umount))
|
umount
|
||||||
|
processes))
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;;
|
;;;
|
||||||
|
@ -153,4 +155,29 @@ constants from <sys/mount.h>."
|
||||||
(when update-mtab?
|
(when update-mtab?
|
||||||
(remove-from-mtab target))))))
|
(remove-from-mtab target))))))
|
||||||
|
|
||||||
|
(define (kernel? pid)
|
||||||
|
"Return #t if PID designates a \"kernel thread\" rather than a normal
|
||||||
|
user-land process."
|
||||||
|
(let ((stat (call-with-input-file (format #f "/proc/~a/stat" pid)
|
||||||
|
(compose string-tokenize read-string))))
|
||||||
|
;; See proc.txt in Linux's documentation for the list of fields.
|
||||||
|
(match stat
|
||||||
|
((pid tcomm state ppid pgrp sid tty_nr tty_pgrp flags min_flt
|
||||||
|
cmin_flt maj_flt cmaj_flt utime stime cutime cstime
|
||||||
|
priority nice num_thread it_real_value start_time
|
||||||
|
vsize rss rsslim
|
||||||
|
(= string->number start_code) (= string->number end_code) _ ...)
|
||||||
|
;; Got this obscure trick from sysvinit's 'killall5' program.
|
||||||
|
(and (zero? start_code) (zero? end_code))))))
|
||||||
|
|
||||||
|
(define (processes)
|
||||||
|
"Return the list of live processes."
|
||||||
|
(sort (filter-map (lambda (file)
|
||||||
|
(let ((pid (string->number file)))
|
||||||
|
(and pid
|
||||||
|
(not (kernel? pid))
|
||||||
|
pid)))
|
||||||
|
(scandir "/proc"))
|
||||||
|
<))
|
||||||
|
|
||||||
;;; syscalls.scm ends here
|
;;; syscalls.scm ends here
|
||||||
|
|
Loading…
Reference in New Issue