zombie processes handled incorrectly

Bug #1624941 reported by pipping on 2016-09-18
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Undecided
Unassigned

Bug Description

This may or may not be related to an issue I reported in August[1] yet never filed as a bug.

I'm attaching a bit of sample code that spawns a process, sends it to sleep, has it continue, kills it, and then waits for it (waiting should immediately return because the process is dead).

Instead, this is the output I get:

Sending signal: +SIGSTOP+
Internal status now: STOPPED (expected: STOPPED)
External status now: [T] (expected: [T])
Sending signal: +SIGCONT+
Internal status now: RUNNING (expected: RUNNING)
External status now: [S] (expected: [S])
Sending signal: +SIGKILL+
Internal status now: RUNNING (expected: SIGNALED)
External status now: [Z] (expected: []/[Z])
Internal status now: RUNNING (expected: SIGNALED)
External status now: [Z] (expected: []/[Z])
If we're lucky, this will terminate at some point...

at which point the repl hangs and never returns. Apparently, waiting for a zombie is not a good idea. It's surprising that I end up with a zombie at all. Moreover, process-status should not be reporting its status as RUNNING. Here's the code (I wrote it such that ideally it would work on sbcl and ccl, for comparison. ccl is mostly okay[2] with it):

#+sbcl (require :sb-posix)

(defconstant +sigkill+
  #+clozure (symbol-value (read-from-string "#$SIGKILL"))
  #+sbcl sb-posix:sigkill)
(defconstant +sigstop+
  #+clozure (symbol-value (read-from-string "#$SIGSTOP"))
  #+sbcl sb-posix:sigstop)
(defconstant +sigcont+
  #+clozure (symbol-value (read-from-string "#$SIGCONT"))
  #+sbcl sb-posix:sigcont)

(defun check-internal-status (process expected)
  (format t "Internal status now: ~a (expected: ~a)~%"
          #+clozure (ccl:external-process-status process)
          #+sbcl (sb-ext:process-status process)
          expected))

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

(defun internal-kill-by-symbol (process signal-symbol)
  (format t "Sending signal: ~S~%" signal-symbol)
  (let ((signal-value (symbol-value signal-symbol)))
    #+clozure (ccl:signal-external-process process signal-value)
    #+sbcl (sb-ext:process-kill process signal-value)))

(defun check-external-status (process expected)
  (let ((pid (get-pid process))
        (stream (make-string-output-stream)))
    (let ((arg-list (list "ps" "-h" "-p" (format nil "~a" pid) "-o" "state")))
      (funcall #+clozure #'ccl:run-program
               #+sbcl #'sb-ext:run-program
               "/usr/bin/env" arg-list :output stream))
    (format t "External status now: [~a] (expected: ~a)~%"
            (string-right-trim '(#\Newline)
                               (get-output-stream-string stream))
            expected)))

(defun wait-for-process (process)
  #+clozure (ccl::external-process-wait process)
  #+sbcl (sb-ext:process-wait process))

(let ((p (funcall #+clozure #'ccl:run-program
                  #+sbcl #'sb-ext:run-program
                 "/bin/sleep" (list "7") :wait nil)))
  (internal-kill-by-symbol p '+sigstop+)
  (sleep 3)
  (check-internal-status p "STOPPED")
  (check-external-status p "[T]")

  (internal-kill-by-symbol p '+sigcont+)
  (sleep 3)
  (check-internal-status p "RUNNING")
  (check-external-status p "[S]")

  (internal-kill-by-symbol p '+sigkill+)
  (sleep 3)
  (check-internal-status p "SIGNALED")
  (check-external-status p "[]/[Z]")

  (sleep 10)
  (check-internal-status p "SIGNALED")
  (check-external-status p "[]/[Z]")

  (format t "If we're lucky, this will terminate at some point...~%")
  (wait-for-process p))

$ sbcl-git --version
SBCL 1.3.9.85-8f36709
$ uname -a
Linux fedora 4.7.0-x86_64-linode72 #1 SMP Thu Aug 4 15:15:18 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
$

* *features*
(:64-BIT :64-BIT-REGISTERS :ALIEN-CALLBACKS :ANSI-CL :ASH-RIGHT-VOPS
 :C-STACK-IS-CONTROL-STACK :COMMON-LISP :COMPARE-AND-SWAP-VOPS
 :COMPLEX-FLOAT-VOPS :CYCLE-COUNTER :ELF :FLOAT-EQL-VOPS
 :FP-AND-PC-STANDARD-SAVE :GENCGC :IEEE-FLOATING-POINT :INLINE-CONSTANTS
 :INTEGER-EQL-VOP :LARGEFILE :LINKAGE-TABLE :LINUX :LITTLE-ENDIAN
 :MEMORY-BARRIER-VOPS :MULTIPLY-HIGH-VOPS :OS-PROVIDES-BLKSIZE-T
 :OS-PROVIDES-DLADDR :OS-PROVIDES-DLOPEN :OS-PROVIDES-GETPROTOBY-R
 :OS-PROVIDES-POLL :OS-PROVIDES-PUTWC :OS-PROVIDES-SUSECONDS-T
 :PACKAGE-LOCAL-NICKNAMES :PRECISE-ARG-COUNT-ERROR :RAW-INSTANCE-INIT-VOPS
 :READ-ONLY-TRAMPS :SB-DOC :SB-EVAL :SB-FUTEX :SB-LDB :SB-PACKAGE-LOCKS
 :SB-SIMD-PACK :SB-SOURCE-LOCATIONS :SB-TEST :SB-THREAD :SB-UNICODE :SBCL
 :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-FIXED-OBJECTS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-VECTORS
 :STACK-GROWS-DOWNWARD-NOT-UPWARD :SYMBOL-INFO-VOPS :UNBIND-N-VOP :UNIX
 :UNWIND-TO-FRAME-AND-CALL-VOP :X86-64)

[1] https://sourceforge.net/p/sbcl/mailman/message/35259260/
[2] http://trac.clozure.com/ccl/ticket/1375#comment:2

Jan Moringen (scymtym) on 2017-09-10
Changed in sbcl:
assignee: nobody → Jan Moringen (scymtym)
status: New → In Progress
Jan Moringen (scymtym) on 2017-09-10
Changed in sbcl:
status: In Progress → Fix Committed
assignee: Jan Moringen (scymtym) → nobody
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers