parent-child.scm hangs pasted by gahr on Wed Oct 16 16:22:25 2024
(import (chicken base) (chicken process) (chicken process-context) (chicken process-context posix) (chicken foreign) (chicken file posix) ) (foreign-declare " #include <sys/types.h> #include <sys/socket.h>") (define make-socketpair (foreign-primitive () " int ends[2] = { -1, -1 }; socketpair(PF_LOCAL, SOCK_STREAM, 0, ends); C_word av[4] = { C_SCHEME_UNDEFINED, C_k, C_fix(ends[0]), C_fix(ends[1]) }; C_values(4, av); ")) (define (write/flush data port) (write data port) (flush-output port)) (define (debug . args) (apply print (current-process-id) ": " args)) (let-values (((p c) (make-socketpair))) (define datum (if (string=? (car (command-line-arguments)) "ok") '() #t)) (print "datum is " datum) (define (child) (let ((out (open-output-file* c)) (in (open-input-file* c))) (debug "sleeping") (sleep 1) (debug "writing to parent") (write/flush datum out) (debug "bye"))) (define (parent child) (let ((out (open-output-file* p)) (in (open-input-file* p))) (debug "reading from " child) (let ((got (read in))) (debug "got '" got "' - bye")))) (let ((pid (process-fork child #t))) (if (zero? pid) (exit) (parent pid))))
bad run (C6) pasted by gahr on Wed Oct 16 16:24:52 2024
> ./parent-child nok datum is #t 80693: reading from 80694 80694: sleeping 80694: writing to parent 80694: bye load: 0.30 cmd: parent-child 80693 [sbwait] 5.64r 0.00u 0.00s 0% 8132k load: 0.30 cmd: parent-child 80693 [sbwait] 5.82r 0.00u 0.00s 0% 8132k load: 0.30 cmd: parent-child 80693 [sbwait] 5.95r 0.00u 0.00s 0% 8132k load: 0.30 cmd: parent-child 80693 [sbwait] 6.10r 0.00u 0.00s 0% 8132k ^C⏎
good run (C5) added by gahr on Wed Oct 16 16:26:11 2024
> ./parent-child nok datum is #t 80832: reading from 80833 80833: sleeping 80833: writing to parent 80833: bye 80832: got '#t' - bye