Question: 1. /* signal_base.c */ 2. #include 3. #include 4. #include 5. #include 6. 7. void handler(int signum) //signal handler 8. { printf(Hello World! ); 9.
1. /* signal_base.c */
2. #include
3. #include
4. #include
5. #include
6.
7. void handler(int signum) //signal handler
8. { printf("Hello World! ");
9. exit(1); //exit after printing
10. }
11.
12. int main(int argc, char * argv[])
13. { signal(SIGALRM,handler); //register handler to handle SIGALRM
14. alarm(1); //Schedule a SIGALRM for 1 second
15. while(1) sleep(5); //waiting for signal to be delivered 16. return 0; //never reached
17. }
Signal Handling Programming Problems Program the solutions to the following problems by extending signal_base.c: 1. Change signal_base.c such that after the handler is invoked, an additional printf("Turing was right! ") occurs in main() before exiting. You will probably need to use a global variable and change the condition on the while loop. Furthermore, change signal_base.c such that every second, first Hello World! prints from the signal handler followed by Turing was right! in main(), over and over again indefinitely. The output should look like: Hello World! Turing was right! Hello World! Turing was Right!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
