Shutdown signals
Tim
tim.oliver at tutanota.com
Tue May 11 06:44:57 UTC 2021
On Monday, 10 May 2021 at 23:55:18 UTC, Adam D. Ruppe wrote:
> On Monday, 10 May 2021 at 23:35:06 UTC, Tim wrote:
>> [...]
>
> dpldocs.info/signal it comes up as the second result.
>
> The C function you call from there (on linux anyway) is
> sigaction. A little copy/paste out of my terminal.d:
>
> ```d
> // I check this flag in my loop to see if an interruption
> happened
> // then i can cleanly exit from there.
> __gshared bool interrupted;
>
> // the interrupt handler just sets the flag
> extern(C)
> void interruptSignalHandler(int sigNumber) nothrow {
> interrupted = true;
> }
>
> // then this code registers the handler with the system
> import core.sys.posix.signal;
> sigaction_t n;
> n.sa_handler = &interruptSignalHandler;
> sigaction(SIGINT, &n, &oldSigIntr); // third arg can
> also be null if you don't care about the old one
> ```
I don't know why I didn't find that. I was searching for the full
name, maybe too specific? Thanks anyways, this is super helpful.
I wish it was documented better though :(
So why use sigaction and not signal? From what I can tell signal
is the C way of doing things
More information about the Digitalmars-d-learn
mailing list