Question: Linux / C Handling SIGALRM PLEASE LOOK AT MY CODE AT THE BOTTOM, USE THAT TEMPLATE. I NEED HELP FINISHING IT #include volatile sig_atomic_t print_flag

Linux / C Handling SIGALRM

PLEASE LOOK AT MY CODE AT THE BOTTOM, USE THAT TEMPLATE. I NEED HELP FINISHING IT

Linux / C Handling SIGALRM PLEASE LOOK AT MY CODE AT THE

#include

volatile sig_atomic_t print_flag = false;

void handler_alarm(int sig) { print_flag = true; }

int main() { signal(SIGALARM,handler); alarm(1);

// infinite for loop: // if statement to check print flag // print // change print flag to false // call alarm function

exit(EXIT_SUCCESS) }

Write a function for handling SIGALRM: According to this link: https://www.secure coding.cert.org/confluence/display/c/SIG31-C.+Do+ not+access shared objects in signal+handlers ccessing or mod can leave data in an inconsistent state. The two exceptions (C Standard, 5.1.2.3, paragraph 5) to this rule are the ability to read from and write to lock-free atomic objects and variables of type "volatile sig atomic-t". Accessing any other type of object from a signal handler is undefined behavior. Therefore, globally define and initialize a flag with type volatile sig atomic-t use a system call to handle signal SIGALIM with the function that you have already defined. use a system call to set an alarm clock for delivery of SIGALRM every one second. use the defined flag and the alarm clock to print the message: Step 1/10 step 2/10 step 2/10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!