Function: proced-children-alist

proced-children-alist is a byte-compiled function defined in proced.el.gz.

Signature

(proced-children-alist PROCESS-ALIST)

Documentation

Return children alist for PROCESS-ALIST.

The children alist has elements (PPID PID1 PID2 ...). PPID is a parent PID. PID1, PID2, ... are the child processes of PPID. The children alist inherits the sorting order of PROCESS-ALIST. The list of children does not include grandchildren.

Source Code

;; Defined in /usr/src/emacs/lisp/proced.el.gz
;;; Process tree

(defun proced-children-alist (process-alist)
  "Return children alist for PROCESS-ALIST.
The children alist has elements (PPID PID1 PID2 ...).
PPID is a parent PID.  PID1, PID2, ... are the child processes of PPID.
The children alist inherits the sorting order of PROCESS-ALIST.
The list of children does not include grandchildren."
  ;; The PPIDs inherit the sorting order of PROCESS-ALIST.
  (let ((process-tree (mapcar (lambda (a) (list (car a))) process-alist))
        ppid)
    (dolist (process process-alist)
      (setq ppid (cdr (assq 'ppid (cdr process))))
      (if (and ppid
               ;; Ignore a PPID that equals PID.
               (/= ppid (car process))
               ;; Accept only PPIDs that correspond to members in PROCESS-ALIST.
               (assq ppid process-alist))
          (let ((temp-alist process-tree) elt)
            (while (setq elt (pop temp-alist))
              (when (eq ppid (car elt))
                (setq temp-alist nil)
                (setcdr elt (cons (car process) (cdr elt))))))))
    ;; The child processes inherit the sorting order of PROCESS-ALIST.
    (setq process-tree
          (mapcar (lambda (a) (cons (car a) (nreverse (cdr a))))
                  process-tree))))