Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help solving this question, the program that needs to be modified is below the question Question 3 [Points 5] Modify and run the program
Need help solving this question, the program that needs to be modified is below the question
Question 3 [Points 5] Modify and run the program shown below in the following way. There is an array of 30 elements defined in the program. The elements of the array are: Thread 1 adds the first five elements [20,18,16,14,12], Thread 2 adds the next five elements [10,8,6,4,2],, Thread 6 adds the last five elements [22,26,30,34,38]. Finally, the sum of all the 30 elements is printed by the main program. The parent must wait for all threads to complete before printing the output. Run and show the output. include \#include \#include > \#define NUM_THREADS 3 int counter=1; void *PrintHello(void *threadid) counter =2 counter+ (int) threadid; printf("'n Thread Id: \%d Counter: \%dln", threadid, counter); pthread_exit(NULL); int main(int argc, char *argv[]) pthread_t threads[NUM_THREADS]; int rc, t; for(t=0;tn ", rc); exit(-1); \} printf("ln Counter: \%dln", counter); pthread_exit(NULL); \} Question 4 [5 points] Run the following program and identify the pid (Process ID) of the parent, child, and grandchild processes. Briefly explain what the program is doing. Run and show output. \#include \#include \#include int main() \{ pid_t pid, pid1, pid2, pid0,pid3,pid4,pid5; / fork a child process */ pid = fork (; ; if ( pidStep 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