Consider the following code segment, how many unique processes and threads are created? How many times...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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); 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);
Expert Answer:
Answer rating: 100% (QA)
This code contains both processes and threads Lets analyze how many unique processes and threads are ... View the full answer
Related Book For
Computer Architecture A Quantitative Approach
ISBN: 978-0123704900
4th edition
Authors: John L. Hennessy, David A. Patterson
Posted Date:
Students also viewed these operating system questions
-
How many unique processes and threads are created in the following program segment? pid_t pid; pid = fork(); if (pid == 0) { /* child process */ fork(); thread.create(); } else { /* parent process */...
-
(A) If the percent yield for the formation of urea in Example 4-13 were 87.5%, what mass of CO 2 , together with an excess of NH 3 would have to be used to obtain 50.0 g CO(NH 2 ) 2 ? (B) Calculate...
-
An old abandoned salt mine, 3.5 106 ft3 in volume, contains air at 520 R, 14.7 lbf/in 2. The mine is used for energy storage so the local power plant pumps it up to 310 lbf/in 2 using...
-
You are provided with a summarized version of the cash account of Lakeside Hospital, a not-for-profit organization for 2018. Prepare a statement of cash flows, using the direct method, for the...
-
Barbara Vigil, Chief Justice, New Mexico Supreme Court Ken Badilla bought a pair of Brahma brand work boots from Wal-Mart on October 19, 2003. The boots packaging had these express descriptions: iron...
-
The Furry Friends Foundation is a non-profit organization that finds homes for abandoned animals that are suitable for adoption. FFF began operations with a bequest from a wealthy gentleman who lived...
-
2 Charlie's Crispy Chicken (CCC) operates a fast-food restaurant. When accounting for its first year of business, CCC created several accounts. Account Name Description Balance Accounts Payable...
-
Assume that the Special Contract Division of Smith experienced the following transactions during the year ended December 31, 2020. i (Click the icon to view the transactions.) Requirements 1. Prepare...
-
Khazanchi is considering an investment proposal with the following cash flows: Initial investment - depreciable assets ........ $90,000 Initial investment - working capital......... 12,500 Net cash...
-
What are the alternatives for barrier's super subs and their pros and cons as well
-
Analyze the concepts and theories used facilitate the change process and sustainability of the change effort
-
How is the research of Trompenaars similar to or different from that of Hofstede? How does knowledge of this research help an IHR professional
-
Day-to-day business operations include daily activities carried out by a company's personnel that contribute to the company's overall success and are in line with its objectives. As a warm-up, write...
-
Evaluating the impact of globalization on HR planning. Explain briefly :- NOTE :- 700 -800 Words -:
-
XYZ Inc., a publicly accountable entity has initiated a defined benefit pension plan for all employees effective January 1, 2019 at an initial cost of $700,000. At the commencement of the plan, the...
-
The column shown in the figure is fixed at the base and free at the upper end. A compressive load P acts at the top of the column with an eccentricity e from the axis of the column. Beginning with...
-
Some directory protocols add an Owned (O) state to the protocol, similar to the optimization discussed for snooping protocols. The Owned state behaves like the Shared state, in that nodes may only...
-
What is performability for the RAID 4 array for offline reconstruction? Calculate the performability using IOPS, assuming a random readonly workload that is evenly distributed across the disks of the...
-
Reorder the instructions to improve performance of the code in Figure 2.35. Assume the two-pipe machine in Exercise 2.3, and that the out-of-order completion issues of Exercise 2.4 have been dealt...
-
The data in Table 2 represent the results of a survey in which 200 people were asked their means of travel to work. (a) Use the survey data to build a probability model for means of travel to work....
-
Sophia has three tickets to a concert, but Yolanda, Michael, Kevin, and Marissa all want to go to the concert with her. To be fair, Sophia randomly selects the two people who can go with her. (a)...
-
Suppose that a survey asked 500 families with three children to disclose the gender of their children and found that 180 of the families had two boys and one girl. (a) Estimate the probability of...
Study smarter with the SolutionInn App