[Openmcl-devel] Sleeping processes never go back to being marked as running

Elias Pipping pipping.elias at icloud.com
Wed Aug 3 10:35:09 PDT 2016


Dear list,

I’m trying to find out how different lisp compilers handle external processes(*). As a part of that, I’ve created a short piece of code that launches an external process, sends it SIGSTOP, asks its about its well-being, and allows its to go about its business again by sending SIGCONT.

I would expect that ccl:external-process-status consequently reports

(1) :running before SIGSTOP is sent
(2) then :stopped
(3) then :running again once SIGCONT was received
(4) and finally :exited.

Indeed, that is what `ps` would do if you ran it on the command line (so I’ve added that to the example for comparison). Here’s the output of my script:

external status: [S] (expected: [S])
internal status: RUNNING (expected: running)
external status: [T] (expected: [T])
internal status: STOPPED (expected: stopped)
external status: [S] (expected: [S])
internal status: STOPPED (expected: running)
external status: [] (expected: [] or [Z])
internal status: EXITED (expected: exited)

My expectations aren’t met in (3): The SIGCONT prompts the process to continue its work but ccl continues to report its status as :stopped, which I find rather confusing.

So I’d like to ask: Is this a bug or intentional?


Elias Pipping

(*) I’m sending a very similar message to sbcl-devel.

PS: Here’s the script that I used:

#+clozure (use-package :ccl)
#+sbcl (use-package :sb-ext)

;; FIXME: this is not portable! Works on linux for now.
;; sbcl has constants but does clozure cl?
(defconstant +sigstop+ 19)
(defconstant +sigcont+ 18)

(defun internal-status (process)
  #+clozure (ccl:external-process-status process)
  #+sbcl (sb-ext:process-status process))

(defun external-kill (pid signal)
  (run-program "/usr/bin/env" (list "kill"
                                    (format nil "-~a" signal)
                                    (format nil "~a" pid))))

(defun external-status (pid)
  (let ((stream (make-string-output-stream)))
    (let ((arg-list (list "ps" "-h" "-p" (format nil "~a" pid) "-o" "state")))
      (run-program "/usr/bin/env" arg-list :output stream))
    (string-right-trim '(#\Newline) (get-output-stream-string stream))))

(defun get-pid (process)
  #+clozure (ccl::external-process-pid process)
  #+sbcl (sb-ext:process-pid process))

(let* ((p (run-program "/usr/bin/env" '("sleep" "3") :wait nil))
       (pid (get-pid p)))
  (format t "external status: [~a] (expected: [S])~%" (external-status pid))
  (format t "internal status: ~a (expected: running)~%" (internal-status p))
  
  (external-kill pid +sigstop+)
  (sleep 1)
  (format t "external status: [~a] (expected: [T])~%" (external-status pid))
  (format t "internal status: ~a (expected: stopped)~%" (internal-status p))

  (external-kill pid +sigcont+)
  (sleep 1)
  (format t "external status: [~a] (expected: [S])~%" (external-status pid))
  (format t "internal status: ~a (expected: running)~%" (internal-status p))

  (sleep 3)
  (format t "external status: [~a] (expected: [] or [Z])~%" (external-status pid))
  (format t "internal status: ~a (expected: exited)~%" (internal-status p)))




More information about the Openmcl-devel mailing list