Import std.os.process_signals
Process
extend
Extend Process
Handlers for the interrupt and terminate signals.
std/os/process_signals.fb, line 15
-
Runs
handlereach time the program is interrupted, by Ctrl+C, or on Windows Ctrl+Break too, which then doesn't end it. A handler runs on a thread of its own, one at a time, and once more for the signals that come while it runs. Once the program's code is done, its coroutines too, none runs, and the signal ends the program again; a call from then on, as from a thread that runs on, does nothing. A coroutine that waits for nothing but what ahandlermay give, a TaskSource's Task, waits for the signal.Examples
Global stopping = Atomic<Bool>(False) Function Stop() stopping.Store(True) End Function Process.OnInterrupt(Stop) While !stopping.Load() // Work, until Ctrl+C. End While -
Runs
handlereach time something asks the program to end, by SIGTERM or SIGHUP, or on Windows by closing its console, as OnInterrupt runs its handler. Windows still ends the program a few seconds after its console closes, and has no SIGTERM to send it. On Linux and macOS, a signal the program started out ignoring, as nohup has it ignore SIGHUP, stays ignored, for OnInterrupt too, and no handler runs for it.
Report an issue with this page or with FutureBlitz on GitHub.