Why we call the signal function in the start of the linux c program? -


the program simple, have handler function named fintr() , program is:

void fintr();  int main() {     int i;     signal(sigint,fintr);     while(1) {         printf("*");     }     return 0; }  void fintr() {     printf("signal received");     exit(1); } 

can put signal(sigint,fintr); @ end of function main()? , why have put in beginning of main()?

putting @ end means come after while (1) ... loop, no, can't put in end, because never executed.

also, pay attention code place inside signal handlers: not safe call printf() inside signal handler.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -