Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sort the lines of code below such that the resulting ordered program compiles, r

ID: 3843427 • Letter: S

Question

Sort the lines of code below such that the resulting ordered program compiles, runs, goes into an infinite loop, and then successfully catches a SIGTERM signal. There is one erroneous line: set it as the LAST line in the program! Note: there are a couple of Top Hat bugs affecting the code below. As before, commas have been replaced with comma look-alikes, and underscores have been replaced with hyphens. This is because these characters are used by the underlying LaTex formatting engine underlying TopHat's data fields ve been assured it's being worked on Drag and drop to order while (1) pause struct sigaction SIGTERM-action 101; 3 C SIGTERM-action. sa-handler catch SIGTERM sigfillset (&SIGTERM-action.; sa mask);

Explanation / Answer

So i've changed some lines of code i.e replaced dot with comma and hyphen with underscore. Hope thats all right. The normal compilers can compile with these.

The correct order is

//F

#include <signal.h>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

// I

void catchSIGTERM(int signo)

{

char * message = "SIGNTERM! ";

write(STDOUT_FILENO, message, 9);

//A

}

//E

int main(int argc, char *argv[])

{


//B

while(1)

pause();

//C

struct sigaction SIGTERM_action = {0};

SIGTERM_action.sa_handler = catchSIGTERM;

sigfillset(&SIGTERM_action.sa_mask);

//D
SIGTERM_action.sa_flags = 0;

//G

sleep(1000);

}

//This line will cause error
//sigaction(SIGTERM, &SIGTERM_action, NULL);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote