Signal handling in Common Lisp
Some set of useful links to do signal handling in Common Lisp with explanations.
Start with https://stackoverflow.com/questions/9950680/unix-signal-handling-in-common-lisp which lists 3 different ways to do this:
- Writing a C-FFI wrapper over the C version directly. (ie, roll your own)
- The function provided by the
cl-async
library: http://orthecreedence.github.io/cl-async/signal-handling. (This may be overkill unless you are already using that library). - The
trivial-signal
library: https://github.com/guicho271828/trivial-signal. This is a standalone library with one job. So, a good choice.
If you are going with trivial-signal
, there are few extra pointers.
- There is a set of examples in this repo, especially useful for both single and multi signal handling.
- We cannot use the top level binding as described in the doc, as documented in this issue.
- With
sbcl
, setting up the handler on the main thread does not work as documented in this issue. But, I have confirmed that this can be sidestepped by setting up the handlers on a different thread (but - need to keep this thread running continuously).