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

Assume INPUTLEN to be 100. main(int ac, char *av[]) { void inthandler (int); voi

ID: 3819832 • Letter: A

Question

Assume INPUTLEN to be 100.

main(int ac, char *av[])

{

void inthandler (int);

void quithandler (int);

char input[INPUTLEN];

int nchars;

signal(SIGINT, inthandler);

signal(SIGQUIT, quithandler);

do {

    printf(" Type a message ");

    nchars = read(0, input, (INPUTLEN - 1));

    if ( nchars == -1)

      perror("read returned an error");

    else {

      input[nchars] = '';

      printf("You typed: %s", input);

    }

}

while(strncmp(input, "quit" , 4) != 0);

}

void inthandler(int s)

{

printf(" Received Signal %d ....waiting ", s);

sleep(2);

printf(" Leaving inthandler ");

}

void quithandler(int s)

{

printf(" Received Signal %d ....waiting ", s);

sleep(3);

printf(" Leaving quithandler ");

}

Q2a. [3 points] What happens if SIGQUIT is generated while the process is in SIGINT handler? Explain WHY.

Q2b. [3 points] What happens if a second SIGINT is generated while the process is still in SIGINT handler? Or a third SIGINT? Explain WHY.

Q2c. [3 points] What happens if a signal is generated while the program is blocking on user input? Explain WHY.

Explanation / Answer

Let me start with signal handiling :

A signal is a software interrupt delivered to a process. The OS uses signals to report exceptional situations to an exceuting program.some signals report errors such as references to invalid memory addresses. other report asynchronous events like disconnection. The C Library defines a variety of signal types. some kind of signals reports the occurrence of an exceptional event.

some of the events that can cause generate or raise a signal:

each of these kind of events generates its own particular kind of signal.

The events that generate signals fall into three major categories: erro, external events and explicit request.

To understand the following Question "What happens if SIGQUIT is generated while the process is in SIGINT handler? Explain WHY."

Let me use the following program

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