Question: Problem 3 : ( 8 pts ) SIGNALS and THREADS Read the C - based pseudo - code that executes on an OUTDATED Linux version.
Problem : pts SIGNALS and THREADS
Read the Cbased pseudocode that executes on an OUTDATED Linux version. Assume that each thread inherits the signal handlers set by the main process just before the call to pthreadcreate, and that that the particular thread is impervious to the changes of signal handlers from other threads or the main process once pthreadcreate has been invoked this is not true for most of the modern OSs but here we work on a fictitious problem For the sake of this problem only, assume that terminating signals that are sent to one thread alone only terminate the thread that handles these.
Also, assume that for signals that need to be handled only once, the algorithm that is used by the OS to select which thread will handle the signal is the following: find the first thread that is not blocking or ignoring the signal selected randomly, but first start from the thread that is now on the processor. Use these assumptions above to answer the questions below the pseudocode presented. Remember, for some of the questions you may need to explore numerous scenarios.
#include
#include
#include
#include
#include
atomiclock;
typedef struct data
char name;
data;
void sigfuncint sig
writeCaught signal no d
sig;
signalsig sigfunc;
void sigfuncint sig
writeCaught signal no d
sig;
void funcdata p
int x;
snprintfpname,dintpthreadself; could also do itoa;
x intptheadselfgetpid lock;
sleep; sleep to catch the signals
int main A
pthreadt tid tid tid;
data ptr;
int pid;
signal SIGINT SIGIGN;
pthreadcreate&tidvoidfunc ptr;
signalSIGSEGV sigfunc;
signalSIGSTOP sigfunc;
pthreadcreate&tidvoidfunc ptr;
signalSIGFPE sigfunc;
signalSIGINT sigfunc;
pthreadcreate&tidvoidfunc ptr;
A
pid getpid;
sleep; Leave time for initializations and executing func for all threads B
pthreadkilltid SIGSEGV; Line A
pthreadkilltid SIGSTOP; Line B
pthreadkilltid SIGSEGV; Line C
pthreadkilltid SIGINT; Line D
pthreadkilltid SIGINT; Line E
sleep;
pthreadjointidNULL;
pthreadjointidNULL;
pthreadjointidNULL;
Part : pts
Q: Which of the three threads is the first to execute func? Why?
Q: Assume that thread tid executes func first ignore lines after A If there is action, who triggers it and who is the recipient? How is it handled?
Part : pts
Once all threads are created, move on to part B For every line in question, ignore all the rest of the lines and describe what happens in main eg when asked about line C ignore lines: A B D E: what signal if any, how and by who it gets handled. Are there more than one possibilities?
Q: Line B: Execute times in a row:
Q: Line D: Execute times in a row:
Part : pts
Ignore lines after B Assume that another user opened a terminal to send to process pid the following signals times each. How do you IMAGINE do not run this because the above program is pseudocode the delivered signal is handled by pid every time? Is there more than one possibility? If so which and why? If not, why not? Q: kill pid;
Q: kill pid;
Q: kill pid;
Solution:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
