[Openmcl-devel] creating a daemon
Eric Blood
eblood at winkywooster.org
Mon Jul 5 08:36:51 PDT 2004
[Long post follows]
I am trying to create an application to run as a daemon at machine
startup. It is going to include allegro serve, swank, and some of my
own components. Here is my starting point:
;;; openmcl -l astest.lisp -e '(make-server)'
(eval-when (:compile-toplevel :load-toplevel :execute)
(require :aserve)
(require :swank))
(in-package :cl-user)
(defclass server-application (ccl::lisp-development-system)
())
(defmethod ccl::toplevel-function ((app server-application)
init-file)
(declare (ignore init-file))
(swank:create-server :port 8001 :dont-close t)
(net.aserve:start :port 8000)
(process-suspend *current-process*))
(defun make-server ()
(ccl:save-application "aserver"
:application-class (find-class 'server-application)
:prepend-kernel t))
First question, is doing a process suspend on the Initial process at
the end of the toplevel-function a good thing? If I don't, the
toplevel-function will be repeatedly called. This is mostly
working--swank is opening a port, but not responding to the inital
handshake, but I am looking into that.
To go a step further, what is the best way to disassociate lisp from
the terminal? Forcibly close the 0, 1, and 2 file descriptors? Or,
is there something I can do with *terminal-io*.
I also have been playing around with forking the process:
(defun fork-test (&optional exit)
(#_fork)
(let ((pid (#_getpid)))
(dotimes (n 5)
(format t "~A: ~A" pid n)
(terpri)
(sleep 1)))
(when exit
(#_exit 0)))
The two things that I observe is that the output from the parent
process is displayed over 5 seconds, and then the child process's
output follows immediately afterward. Some sort of locking? And if I
exit from the parent process, both the parent and child close. Is
this behavior also terminal related? If so, I can understand the
blocking of the child output, but why would the child process exit
when the parent process exits?
Welcome to OpenMCL Version (Beta: Darwin) 0.14.2-p1!
? (fork-test)
1959: 0
1959: 1
1959: 2
1959: 3
1959: 4
NIL
? 1961: 0 <-- at this point the ouput of
the child
1961: 1 shows immediately
1961: 2
1961: 3
1961: 4
NIL
? (fork-test t) <-- run tests, but have the
parent exit
1959: 0
1959: 1
1959: 2
1959: 3
1959: 4
car:/Users/eblood/lisp/server
$
--
eblood
More information about the Openmcl-devel
mailing list