October 26, 2024
Chicago 12, Melborne City, USA
C#

Two compilers (clang vs gcc) have different api for signals?


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?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video