by matheusmoreira · 3y ago · 0 comments
Though I generally agree with the sentiment, there are other limited but still useful things you can do, for example write() is allowed:
const char msg[] = "\ncaught signal, finishing..\n";
write(2, msg, sizeof(msg)); // 1 == stdout, 2 == stderrNowadays signalfd and pidfd are the better options.
I've successfully used this technique in Polyphony [1], a fiber-based Ruby gem for writing concurrent programs. When a signal occurs, Polyphony creates a special-purpose fiber that runs the signal handling code. The fiber is put at the head of the run queue, and is resumed once the currently executed fiber yields control.