Lisp中的Unix信号处理 [英] Unix signal handling in (common) lisp
问题描述
我已经对该主题进行了一些研究,并且发现了空白.在Common Lisp中,似乎有与实现相关的方式来进行Unix信号处理,但是是否有一个软件包提供了一种交叉实现方式来进行信号处理?
I've done a bit of research on this subject and am turning up blanks. There seem to be implementation-dependent ways of doing Unix signal handling in Common Lisp, but is there a package that gives a cross-implementation way of doing signal handling?
我主要想听SIGINT并在我的应用程序中正常关闭.我正在linux上使用Clozure CL 1.7 ...就像提到的那样,这对于一个用于此的软件包将是一个很好的选择,但是如果我必须诉诸于实现特定的代码,那很好.
I would mainly like to listen for SIGINT and do a graceful shutdown in my app. I'm using Clozure CL 1.7 on linux...like mentioned, it would be great for a package for this, but if I have to resort to implementation-specific code, that's fine.
我也不完全同意使用SIGINT(尽管很理想).如果需要,我可以使用另一个信号.
I'm also not completely married to using SIGINT (although it's ideal). I can use another signal if needed.
如果这很麻烦,是否有人有其他建议可以优雅地从应用程序外部关闭Lisp应用程序?我的一个主意是创建一个应用程序监视的文件,但是如果它检测到该文件,它将关闭...有点黑.
If this is going to be messy, does anyone have any other suggestions for gracefully shutting down a lisp app from outside the app? One idea I had is to create a file the app monitors for, and if it detects the file, it shuts down...kind of hacky, though.
谢谢!
推荐答案
我也找不到用于信号处理的通用库.但是,对于大多数Lisp实现, Slime 实现了创建自定义SIGINT
处理程序".通过查看该代码的CCL情况,我发现了ccl:*break-hook*
. ccl:*break-hook*
不在文档中,但是在此处中找到了引入它的提交.
I can't find a general library for signal handling either. However, Slime implements "create a custom SIGINT
handler" for most Lisp implementations. By looking at the CCL case of that code, I found ccl:*break-hook*
. ccl:*break-hook*
is not in the documentation, but the commit it was introduced in is located here.
这个简单的示例代码可在我的系统上使用(CCL 1.8,linux x86):
This trivial example code works on my system (CCL 1.8, linux x86):
(setf ccl:*break-hook*
(lambda (cond hook)
(declare (ignore cond hook))
(format t "Cleaning up ...")
(ccl:quit)))
将此代码输入到非史莱姆REPL中后,发送SIGINT
将导致程序打印正在清理..."并退出.
After this code is entered into a non-Slime REPL, sending SIGINT
will cause the program to print "Cleaning up ..." and exit.
这篇关于Lisp中的Unix信号处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!