Question
Process vs. Thread (35 points): What is the address space of a process (5 points)? What part of the address space of a process are
Process vs. Thread (35 points): What is the address space of a process (5 points)?
What part of the address space of a process are shared by all threads in the process (5
points)?
#include
#include
int value = 0;
void *runner(void *param); /* the thread */
int main(int argc, char *argv[])
{
pthread_t tid; /* the thread identifier */
pthread_attr_t attr; /* set of attributes for the thread */
int pid;
value = value + 2;
pid = fork();
if(pid == 0) { /* child process */
pthread_attr_init(&attr);
pthread_create(&tid,&attr,runner,argv[1]);
pthread_join(tid,NULL);
printf("CHILD: value = %d", value); /* LINE C */
}
else if (pid > 0) { /* parent process */
wait(NULL);
printf("PARENT: value = %d", value); /* LINE P */
}
}
void *runner(void *param) {
value = value + 6;
pthread_exit(0);
}
The above program uses the Pthreads API. What would be the output from the program at
LINE C and LINE P (10 points)? Explain your answer (15 points).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started