Shutdown signals

Adam D. Ruppe destructionator at gmail.com
Mon May 10 23:55:18 UTC 2021


On Monday, 10 May 2021 at 23:35:06 UTC, Tim wrote:
> I can't find that in the docs, nor in dpldocs. Can you help out 
> with this?

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
```


More information about the Digitalmars-d-learn mailing list