Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Trace the output for the C program in Figure , and answer the following questions: What is the output of Line A ? What is

Trace the output for the C program in Figure , and answer the following questions:
What is the output of Line A ?
What is the output of Line B ?
What is the final value of glob_data before the program is terminated?
image text in transcribed
1 #include 2 #include 3 #include 4 #include 5 #include 6 7 int glob_data = 0; 8 9 void *runnerfunc(void *p) { 10 glob_data - 5; 11 pthread_exit(); 12 13 14 int main() 15 BU 16 int pid; 17 pthread_t tid; 18 pthread_attr_t attr; 20 pid - fork(); 21 if (pid - ) 22 pthread_attr_init(&attr); 23 pthread_create(&tid, &attr,runnerfunc, NULL); 24 pthread_join(tid, NULL); 25 printf("CHILD: value = $d ",glob_data); /* LINE A */ 26 } else if (pid > 0) { 27 wait (NULL); 28 printf("PARENT: value = $d ",glob_data); /* LINE B / 29 } 30 return 0; 31 Figure 2 C-Code for Exercise A-2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions