Question: Consider the following code segment, how many unique processes and threads are created? How many times the sum will be printed and what are

Consider the following code segment, how many unique processes and threads are created? How many times the 

Consider the following code segment, how many unique processes and threads are created? How many times the sum will be printed and what are its values assuming that the user entered a value 20 for param? #include #include #include #include #include int sum=10; void *runner(void *param) { sum += atoi(param); printf("Thread sum = %d ", sum); pthread_exit(0); } int main(int argc, char *argv[]) { pthread_t tid; pthread_attr_t attr; pthread_attr_init(&attr); pid_t pidl, pid2; pidl = fork(); if(pid 1 == 0) { /* child process */ fork(); pthread_create(&tid, &attr, runner, argv[1]); pthread_join(tid, NULL); } else wait(NULL); pid2 = fork(); if(pid2 >0) wait(NULL); printf("Process sum = %d ", sum); return (0);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This code contains both processes and threads Lets analyze how many unique processes and threads are ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!