Write a C code as described below I am trying to print out a statement \"Good Mo
ID: 3887966 • Letter: W
Question
Write a C code as described below I am trying to print out a statement "Good Morningt from function 1 func) and "Good Bye" from function 2 unc2) in the program However, due to the infinite loop that I made by mistake in the program funci,Ican not see the second statement "Good Bye!". The interrupt handler that I added to deal with the signal (control 'c to kill the foreground process stops the infinite loop but couldn't see Good Byel". The program and the output after executing the program are as follows. w Program Finclude csignal.h #indude "tipi,hdrh" void intHandler) exit EXIT SUCCESS) void funci0 while(1)( infinite loop made by mistake sleep(1): void funcz0 printl Good Byel: exit EXIT SUCCESS) int main(int argc·char·argvU) { signal calls interrupt handler (intilandler) when contro-Ys typed-/ signal[SIGINT, intHandler) funci func20 exit EXIT SUCCESS) Good Mormning Looping- ACThis is an interupt handler Modify the above program so that it can print out "Good Bye" as specified at fc2 even though the program is badly written with the infinite loop statement The Output should like, w.Output Good Morning Looping- "CThis is an interrupt handler Good ByeExplanation / Answer
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include "tlpi_hdr.h"
#include <setjmp.h>
jmp_buf bufferA;
void intHandler() {
printf("This is an interrupt handler ");
longjmp(bufferA, 1);
exit(EXIT_SUCCESS);
}
void func1() {
printf("Good Morning ");
while (1) {
printf("Looping... ");
sleep(1);
}
}
void func2() {
printf("Good Bye ");
exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[]) {
signal(SIGINT, intHandler);
if (!setjmp(bufferA)) {
func1();
func2();
}
else {
func2();
}
exit(EXIT_SUCCESS);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.