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
-
Dell Farms Ltd . sold equipment during 2 0 2 2 that had originally been purchased for $ 2 5 2 , 0 0 0 . The equipment had a net book value of $ 1 4 4 , 0 0 0 at the time of the sale when it sold for...
-
Dumlup nar Enterprise issued a loan with a nominal value of 5 , 0 0 0 , 0 0 0 TL , 6 % nominal interest and a 5 - year maturity on January 1 , 2 0 2 0 . Bond principal payment will be made at the end...
-
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...
-
The Fed uses a targeted federal funds rate when implementing monetary policy. However, the Fed's main purpose in its monetary policy is typically to have an impact on the aggregate demand for...
-
Section 17-12 showed how nucleophilic aromatic substitution can give aryl amines if there is a strong electron-withdrawing group ortho or para to the site of substitution. Consider the following...
-
What problems to be aware of when accessing social media sites?
-
Reba Dixon is a fifth grade school teacher who earned a salary of $38,000 in 2017. She is 45 years old and has been divorced for four years. She received $1,200 of alimony payments each month from...
-
Good day dear tutor, please answer all the requirements , I deeply appreciat it thank you so much! Financial mix ratios. The data given below were obtained from the financial records of Menace V....
-
Nautilus Resources is investing in a new heavy oil upgrader in northern Alberta. Nautilus has hired Rite Build Contractors to construct the facilities. The contract price is $3,600 million to be...
-
Smith Company expects to sell 5,000 units Each unit requires: 2 pounds of direct material at $10 per pound 2 direct labor hours at $12 per credit labor hour The manufacturing overhead rate is $7 per...
-
Assume that a perfectly competitive market in long-run equilibrium with firms earning zero profit experiences a sudden increase in demand for its good. in marginal revenue will cause firms to As a...
-
An organization has a class C network id 200.9,15 and wants to design subnets for four departments with the following requirements. Department Marketing Finance Sales IT Number of hosts 90 41 29 18...
-
Two particles are fixed to an x axis: particle 1 of charge -5.80 x 107 C is at the origin and particle 2 of charge +5.80 x 107 C is at x2- 20.0 cm. Midway between the particles, what is the magnitude...
-
Cash $3,240 Accounts Receivable 3,924 Supplies 3,672 Prepaid Insurance 1,800 Equipment 7,680 Accum. Depr. - Equipment $1,296 Accounts Payable 1,014 Long Term Notes Payable 8,400 Common Stock 2,400...
-
A 0.00290 kg air-inflated balloon is given an excess negative charge q = -3.00 x 10-8 C by rubbing it with a blanket. It is found that a charged rod can be held above the balloon at a distance of d =...
-
Francois and Marielle Sheppelle are in their mid-fifties. Both are elementary school teachers and are close to retirement. Francois's annual salary is $125,000, and Marielle's is $105,000. They have...
-
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...
-
A sample of students is enrolled in an online statistics class, and another sample is enrolled in a traditional statistics class. At the end of the semester, the students are given a test. The scores...
-
A sample of 87 one-year-old spotted flounder had a mean length of 126.31 millimeters with a sample standard deviation of 18.10 millimeters, and a sample of 132 two-year-old spotted flounder had a...
-
The mean speed for a sample of 39 cars at a certain intersection was 26.50 kilometers per hour with a standard deviation of 2.37 kilometers per hour, and the mean speed for a sample of 142...
Study smarter with the SolutionInn App