Having this in c:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
void handler(int num){
write(1, "I won't die!\n", 13);
}
int main(){
signal(SIGINT, handler);
while(1){
printf("wastings cycles. %i\n",getpid());
sleep(1);
}
}
If compiled with gcc, then for the first time the ^C is pressed, the handler gets activated and thus print
wastings cycles. 19361
^CI won't die!
but for the second time the C^ is pressed, it will die:
wastings cycles. 19361
^C
Command terminated
Tha is for gcc. However for compiled with clang:
wastings cycles. 22247
^CI won't die!
wastings cycles. 22247
^CI won't die!
wastings cycles. 22247
^CI won't die!
wastings cycles. 22247
^CI won't die!
wastings cycles. 22247
^CI won't die!
wastings cycles. 22247
^CI won't die!
wastings cycles. 22247
^CI won't die!
It never dies. Why? It is the same source, the same hader signal.h
, but other compiler uses different output. Gcc != clang. Can someone explain me why the difference?