I found a simple common lisp preforking server (http://tomayko.com/writings/unicorn-is-unix) and gave wart the primitives necessary to make it clean: (def start-server()
(w/socket s 1978
(repeat 2
(fork (thunk
(handle-request s))))
(wait-for-children)))
(def handle-request(socket)
(accepting stream :from socket
(format stream "Hello ~A, this is PID ~D~%"
(read-line stream) (sb-posix:getpid))
(flush stream)))
https://github.com/akkartik/wart/blob/f5fe0903ebce7001ee2efd03f549f4190d389f20/068prefork.wartTo try it out (you'll need SBCL): $ git clone https://github.com/akkartik/wart.git
$ cd wart
$ git checkout bcad0b2b1752765271987c8fe95f3d47c54c46e2
$ wart
wart> (start-server)
In a new tty: $ wart
wart> (client)
"Hello PID ccc, this is PID sss"
wart> (client)
"Hello PID ccc, this is PID ttt" ; different server process
Let me know if you have alternative API suggestions, especially for accepting, my take on the UNIX accept() call. |