Reputation: 4020
D's (rather sparse) official documentation doesn't have anything about handling system signals on *nx or Windows.
The system
module only has Endian
and OS
, syserror
is deprecated / only for Windows errortext, and signals
is about message-passing, not system signals.
Is there a way (in pure D) to install a signal handler, to capture and allow me to react to certain signals at runtime, or, at least a way to detect that a signal was recieved and an exception I can catch
?
i.e, in Python, a simple example is:
import signal
signal.signal(signal.SIGSEGV, myFunctionToHandleSEGV)
# ...
Upvotes: 3
Views: 165
Reputation: 25595
It is the same as in C, just with an import instead of an include. Find a C example that looks interesting to you, then change #include<signal.h>
to import core.stdc.signal;
if you are using just the standard C signal
function, or import core.sys.posix.signal;
if you are using Posix functions like sigaction
, then remember to mark your callback (if you use one) with extern(C)
(and in recent versions of D, @nogc nothrow
too), and then the rest of the code should compile as D the same way as in C.
Upvotes: 5