digitalmars.D.learn - Shutdown signals
- Tim (3/3) May 10 2021 Hi all,
- Adam D. Ruppe (3/6) May 10 2021 import core.sys.posix.signal; then you can use the same functions
- Tim (3/10) May 10 2021 I can't find that in the docs, nor in dpldocs. Can you help out
- Adam D. Ruppe (21/23) May 10 2021 dpldocs.info/signal it comes up as the second result.
- Tim (6/28) May 10 2021 I don't know why I didn't find that. I was searching for the full
- Patrick Schluter (5/12) May 10 2021 Use `sigaction()`, `signal()` has problems. See this
- Tim (2/16) May 11 2021 Thanks a lot!
Hi all, How can I get a D program to detect something a keyboard interrupt so I shut things down in a specific way?
May 10 2021
On Monday, 10 May 2021 at 23:20:47 UTC, Tim wrote:Hi all, How can I get a D program to detect something a keyboard interrupt so I shut things down in a specific way?import core.sys.posix.signal; then you can use the same functions as C to set signal handlers.
May 10 2021
On Monday, 10 May 2021 at 23:31:11 UTC, Adam D. Ruppe wrote:On Monday, 10 May 2021 at 23:20:47 UTC, Tim wrote:I can't find that in the docs, nor in dpldocs. Can you help out with this?Hi all, How can I get a D program to detect something a keyboard interrupt so I shut things down in a specific way?import core.sys.posix.signal; then you can use the same functions as C to set signal handlers.
May 10 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 ```
May 10 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: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[...]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 ```
May 10 2021
On Tuesday, 11 May 2021 at 06:44:57 UTC, Tim wrote:On Monday, 10 May 2021 at 23:55:18 UTC, Adam D. Ruppe wrote:Use `sigaction()`, `signal()` has problems. See this stackoverflow [1] question explains the details [1]: https://stackoverflow.com/questions/231912/what-is-the-difference-between-sigaction-and-signal[...]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
May 10 2021
On Tuesday, 11 May 2021 at 06:59:10 UTC, Patrick Schluter wrote:On Tuesday, 11 May 2021 at 06:44:57 UTC, Tim wrote:Thanks a lot!On Monday, 10 May 2021 at 23:55:18 UTC, Adam D. Ruppe wrote:Use `sigaction()`, `signal()` has problems. See this stackoverflow [1] question explains the details [1]: https://stackoverflow.com/questions/231912/what-is-the-difference-between-sigaction-and-signal[...]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
May 11 2021