I have infinite loop program written in D:
$ cat dprog.d
import std.stdio;
import core.thread;
void main()
{
while(1){
Thread.sleep(dur!("seconds")(1));
};
}
When I build and run this program on Linux (Ubuntu), kill -10 $PID
has no effect on it. And indeed, it does catch a bunch of signals by default:
$ cat /proc/$PID/status | grep SigCgt
SigCgt: 0000000180000a00
Signal 10 is a SIGUSR1
signal, for which the default action is process termination (consult man 7 signal
).
Equivalent program, written in C terminates on kill -10 $PID
and its cat /proc/$PID/status | grep SigCgt
is SigCgt: 0000000000000000
.
Equivalent program, written in Rust also terminates on kill -10 $PID
, however its cat /proc/$PID/status | grep SigCgt
is SigCgt: 0000000180000440
.
My question is: does D (Rust) compiler register default signal handlers? If yes, why? Also, is this documented somewhere?
Signal handlers can be specified for all but two signals (SIGKILL and SIGSTOP cannot be caught, blocked or ignored). If the signal reports an error within the program (and the signal is not asynchronous), the signal handler can terminate by calling abort() , exit() , or longjmp() .
*/ . . /* set a signal handler for ALRM signals */ signal(SIGALRM, catch_alarm); /* prompt the user for input */ printf("Username: "); fflush(stdout); /* start a 30 seconds alarm */ alarm(30); /* wait for user input */ gets(user); /* remove the timer, now that we've got the user's input */ alarm(0); . . /* do something ...
It returns back to where it was in your code when the signal was triggered. Many libraries and applications exploit the same mechanisms to implement threadless multitasking (for instance libmill).
The docs for core.thread.thread_setGCSignals tell us that, on Posix systems, SIGUSR1 and SIGUSR2 are used for the runtime to control suspending and resuming threads for GC purposes.
This function allows you to change which signals are used, in case there are different signals you don't need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With