On Friday, 8 April 2016 at 16:16:27 UTC, Adam D. Ruppe wrote:
On Friday, 8 April 2016 at 15:31:13 UTC, Puming wrote:
The D version behavior is strange.

Are you still calling bash? Cuz that is going to complicate things a lot because bash does its own signal handling too and could be intercepting it.

No, this happens in a simple demo program:

import std.stdio;
import std.process;
import core.stdc.signal;
import core.thread;
import std.datetime;


extern(C) void sig_hand(int signal) nothrow @nogc @system {
    import core.stdc.stdio: printf;
    printf("signal %d catched!\n", signal);
}

void main() {
    if (signal(SIGINT, &sig_hand) == SIG_ERR) {
        writeln("can't catch SIGINT");
    }

    string line;
    write("> ");
    while(1) {
        Thread.sleep(1.seconds);
    }
}

But after trying again on my machine, it behaved the same as in the C code.

Maybe I got the wrong behavior last night due to running it on a remote server.


When Using while with readln, after hitting Ctrl-C, the next readln will throw exception:

This is normal though. If a signal interrupts a read/write call, it returns an error saying it was interrupted so you can choose to abort or try again. (this way you can catch ctrl+c to cancel input)

Thanks, so I'll just catch it.


Reply via email to