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!
2. Write a new program based on your signal_base.c that after exiting (via CTRL-C), will print out the total time the program was executing in seconds. To accomplish this task, you will need to register a second signal handler for the SIGINT signal, the signal that is delivered when CTRL-C is pressed. Conceptually, your program will request a SIGALRM signal to occur every second, tracking the number of alarms delivered, and when the program exits via CTRL-C, it will print how many alarms occurred, or the number of seconds it was executed. Name your programs YourLastName_YourFirstName_Lab02-1.c and YourLastName_YourFirstName_Lab02-2.c You must include a comment on the top of your program like the following: /* CMPS 3600 OS Lastname Firstname Lab 02 */ Create a Makefile for your program and a README file explaining the basics about your program. The submission of all your files including your report will be through the Blackboard. The report should include screenshots and a conclusion assessing the importance of the signals. Its better if you submit your report in a PDF.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started