~ salmonella-environment-setup (master) /scripts/common/kill-orphan.scm
Trap1(use extras posix srfi-1 srfi-13)23(define salmonella-home4 ;; Change this to the directory where salmonella builds run. This5 ;; is the path on the Linux machines.6 "/home/chicken/salmonella/build/salmonella-run-publish/")78(define max-attempts-to-kill 10)910(define (get-pids)11 (filter-map string->number (directory "/proc")))1213(let ((pids (get-pids)))14 (for-each15 (lambda (pid)16 (handle-exceptions exn17 #f ;; ignore18 (let* ((status-file (sprintf "/proc/~a/status" pid))19 (parent-pid20 (let loop ((lines (with-input-from-file status-file21 read-lines)))22 (if (null? lines)23 #f24 (let ((line (car lines)))25 (if (string-prefix? "PPid:" line)26 (string->number (cadr (string-split line)))27 (loop (cdr lines)))))))28 (command-line29 (with-input-from-file (sprintf "/proc/~a/cmdline" pid)30 read-line)))31 (if (and (eq? parent-pid 1)32 (string-prefix? salmonella-home command-line))33 (let loop ((i 1))34 (if (> i max-attempts-to-kill)35 (printf "Giving up at attempting to kill ~a\n" pid)36 (begin37 (printf "Killing ~a: ~a [cwd: ~a] (attempt ~a out of ~a)\n"38 command-line39 (read-symbolic-link (sprintf "/proc/~a/cwd" pid))40 pid i max-attempts-to-kill)41 (process-signal pid signal/kill)42 (when (memv pid (get-pids))43 (loop (fx+ i 1))))))))))44 pids))