Question: Save a CL image without exiting the environment

Question

Save a CL image without exiting the environment

Answers 1
Added at 2017-01-05 13:01
Tags
Question

I want to save a "snapshot" of the current environment so I can play with it later without consequences for messing it up. (Essentially creating a sandbox)

I know that I can save the image with (save-lisp-and-die "sbcl.core"). I also know that I can then load the image with sbcl --core sbcl.core.

The problem is that I have running threads that I cannot afford to stop even for a second and this command will exit sbcl.

My question is: Can I create an image without exiting the environment? I am looking for something like (save-lisp "sbcl.core")

If there is a portable way to do that - it would be great. If not - I am interested in a solution for SBCL.

Answers
nr: #1 dodano: 2017-01-05 13:01

SBCL core saving gives the following function, based on SBCL manual's advice:

(defun save-core (core-fn)
  (progn
    #+sbcl
    (let ((fork-result (sb-posix:fork)))
      (case fork-result
        (-1 (error "fork failed"))
        (0 (sb-ext:save-lisp-and-die core-fn :toplevel #'main :executable t))
        (otherwise (sb-posix:wait)))
      (format t "stand-alone core ~a saved" core-fn))
    #-sbcl
    (error "not available on this lisp")
    (values)))

Unfortunately it might not work with running threads.

Source Show
◀ Wstecz