[plt-scheme] How to handle a Unix kill signal?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jul 13 11:19:35 EDT 2006

At Thu, 13 Jul 2006 10:27:13 -0400, Marin Simina wrote:
> I am trying to write an event handler which is supposed to catch a  
> Unix kill signal. I am using mzscheme. Any ideas?

You mean the TERM signal, I guess?

I don't think it can be done without writing a bit of C code. You could
try accessing sigaction() through `(lib "foreign.ss")', but Scheme code
is certainly not safe to run as a signal handler.

The simplest way to communicate the signal to Scheme is to translate it
to a break exception just like the INT signal. To do that, write a
little extension in C that installs signal handler to call


If you need to distinguish TERM signals from INT signals, you could
have the signal handler set a flag and just call
scheme_signal_received(). Then, you'd also have to implement a new kind
of event that polls the flag; use scheme_add_evt(). Finally, in Scheme,
`sync' on the event to detect TERM signals.


Posted on the users mailing list.