RENDER THIS CODE TO LINUX/C Runnable code. No questions. Just C file please. Her
ID: 3708524 • Letter: R
Question
RENDER THIS CODE TO LINUX/C Runnable code. No questions. Just C file please.
Here you are provided the following PSEUDO-CODE. Render this code to actual LINUX/C runnable code and execute it on your machines. Solve all questions asked below, report your results, and also fully justify them by searching on your online resources, manuals, textbooks, and figuring out how signal:s behave for the multi-thread situation. Your results are not going to be accepted as correct unless fully justified. #include #include #include #include name, 1e,, (int)pthread_selfo); could also do itoa) p->age-CycleTimer::currentseconds ); x = (int) (( (int)pthread-self()-getpid())/((getpid()*(int)test-and-set(&lock;))); sleep(5e); 1Sleep to catch the signals int main) pthread t tidi, tid2, tid3; pthread attr t attr; data d; data.ptr=&d; int pid, lock-e; signal (SIGINT,SIG IGN); pthread create(&tidi;,&attr;, (void)func,ptr) signal(SIGSEGV, sig_func); signal(SIGSTOP,sig_func); pthread create(&tid2;,&attr;, (void)func,ptr); signal (SIGFPE,sig func) signal (SIGALRM, sig func2); signal (SIGINT, sig func2); pthread create(&tid3;,&attr;, (void)func,ptr); pid getpid); sleep(1e); // Leave time for initializations and executing func for all threads pthread_kill (tid1,SIGSEGV) II Line A sleep(5) pthread kill(tid2,SIGSTOP) /Line B alarm(3); while(lalrmflag) pauseo; pthread_ kill(tid1,SIGINT) pthread_ kill(tid3,SIGINT) sleep(4e); pthread join(tid1, NULL) pthread_join(tid2, NULL): pthread_join(tid3, NULL): // Line C (1) // Line C (2) /I Line D // Line EExplanation / Answer
#include<pthread.h>
#include<unistd.h>
#include<sys/types.h>
#include<stdio.h>
#include<signal.h>
#include"CycleTimer.h "
typedef struct data {
char name[10];
double age;
}data;
int alrmflag = 0;
void sig_func(int sig) {
write(1,"Cought signal no. = %d ",sig);
signal(sig,sig_func);
}
void sig_func2(int sig) {
write(1,"Cought signal no. = %d ",sig);
alrmflag = 1;
}
void func (data *p) {
int x;
snprintf(p->name, 10,"%d",pthread_self());
p->age = CycleTimer::CurrentSeconds();
x= (int)(((int)pthread_self()+getpid())/((getpid()*(int)test_and_set(&lock))));
sleep(50);
}
int main() {
pthread_t tid1, tid2, tid3;
pthread_attr_d attr;
data d;
data *ptr = &d;
int pid,lock = 0;
signal(SIGINT,SIG_IGN);
pthread_create(&tid1,&attr,(void*)func,ptr);
signal(SIGSEGV,sig_func);
signal(SIGFPE,sig_func;
pthread_create(&tid2,&attr,(void*)func,ptr);
signal(SIGFPE,sig_func);
signal(SIGALRM,sig_func2);
signal(SIGINT,sig_func2);
pthread_create(&tid3,&attr,(void*)func,ptr);
pid = getpid();
sleep(10);
pthread_kill(tid1,SIGSEGV);
sleep(5);
pthread_kill(tid2,SIGSTOP);
alarm(3);
while(!alrmflag) pause();
pthread_kill(tid1,SIGINT);
pthread_kill(tid3,SIGINT);
sleep(40);
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
pthread_join(tid3,NULL);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.