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

Operating System Concept : The following code segment is the part of the program

ID: 3854379 • Letter: O

Question

Operating System Concept :

The following code segment is the part of the program.

What are the succeeding 3 program counter, in term of line number in this program, after the program executes the instructions on Line X?

When the system call is interrupted by a signal, will the system call be resumed after the signal is caught? If yes, please illustrate the procedure to resume. Otherwise, please describe how the operating system terminates the system call.

The A and B part in the above code segment can be separated into multiple processes or multiple threads. Please describe how the measured flow in A part can be sent to B part when multiple process and multiple thread are used.

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

int main(int argc, char **argv){
void catch(int);
int a;
  
printf("Hello Taipei!! ");
  
signal(SIGSEGV, catch);
/*
A part : measure the traffic flow
*/
  
a = *(int *) 0; // LINE X
  
/*
B part : change the traffic light
*/
}

void catch(int snum){
printf("Oooops, there is an illegal memory access(%d). ", snum);
raise(SIGSTOP);
exit(0);
}

Explanation / Answer

Yes,the system call will be resumed after the signal is caught.

You don't need to resume it separately.You just need to handle the signal properly.

But, for this program, the system call won't be resumed because here the signal is caught and but in the function , the handler causes to terminate the program
Instead you need to handle the signal using signal handler in such a way that the program will be solved and it returns a value.So,the control will then continue the normal execution

Here,A and B are considered to be as concurrent applications.So, flowchart would be like for two separate programs running parallely with time slice for each program