Catching signals with D

Heywood Floyd soul8o8 at
Thu Dec 22 18:31:32 PST 2011

On 12/22/11 23:51 , Matej Nanut wrote:
> Hello everyone, I've been fascinated by D lately and have been using it
> for all
> my school assignments (like simple ray casting and simulated annealing).
> What I can't find anywhere is how to do something like
> "signal(SIGINT, myhandler)" (I'm in a Linux environment).
> I need this to stop the annealing process early but still keep the
> current best
> result. Is there a better way to interrupt my program?
> Thanks!
> Matej
> P.s. I hope I sent this to the appropriate address. :)


I don't know of any official way, but since D links against the c 
runtime you can just hook up functions from there, I believe. This works 
on osx at least:

import	std.stdio;

extern(C) void signal(int sig, void function(int) );

// Our handler, callable by C
extern(C) void handle(int sig){

void main()
	enum SIGINT = 2; // OS-specific


$ rdmd sig.d

$ _


More information about the Digitalmars-d-learn mailing list