On Saturday, 2 December 2017 at 00:41:19 UTC, Wanderer wrote:
Is there any method to cleanup on Ctrl-C?

// ----------------------------------
import std.stdio;
import core.thread;

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

extern(C) void handle(int sig)
{
writeln("Control-C was pressed..aborting program....goodbye...");
    // do more stuff?
    exit(-1);
}

void main()
{
    enum SIGINT = 2;
    signal(SIGINT,&handle);

    scope (exit){ writeln("Cleanup"); }

    writeln("Waiting...");
    Thread.sleep(10.seconds);
    writeln("Done waiting...");
}
// ---------------------------------

Reply via email to