Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Repeat Exercise 3.22, this time using Windows shared memory. In particular, using the producer-consumer strategy, design two programs that communicate with shared memory using the Windows API as outlined in Section 9.7.2. The producer will generate the numbers specified in the Collatz conjecture and write them to a shared memory object. The consumer will then read and output the sequence of numbers from shared memory. In this instance, the producer will be passed an integer parameter on the command line specifying how many numbers to produce (for example, providing 5 on the command line means the producer process will generate the first five numbers).

Exercise 3.22

In Exercise 3.21, the child process must output the sequence of numbers generated from the algorithm specified by the Collatz conjecture because the parent and child have their own copies of the data. Another approach to designing this program is to establish a shared-memory object between the parent and child processes. This technique allows the child to write the contents of the sequence to the shared-memory object. The parent can then output the sequence when the child completes. Because the memory is shared, any changes the child makes will be reflected in the parent process as well.
This program will be structured using POSIX shared memory as described in Section 3.5.1. The parent process will progress through the following steps:

a. Establish the shared-memory object (shm open(), ftruncate(), and mmap()).

b. Create the child process and wait for it to terminate.

c. Output the contents of shared memory.

d. Remove the shared-memory object.

One area of concern with cooperating processes involves synchronization issues. In this exercise, the parent and child processes must be coordinated so that the parent does not output the sequence until the child finishes execution. These two processes will be synchronized using the wait() system call: the parent process will invoke wait(), which will suspend it until the child process exits.

Exercise 3.21

The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm:

496_4c6908f1-6cd9-46ec-9792-99e0d6e92a8a.png

The conjecture states that when this algorithm is continually applied, all positive integers will eventually reach 1. For example, if n = 35, the sequence is

35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1

Write a C program using the fork() system call that generates this sequence in the child process. The starting number will be provided from the command line. For example, if 8 is passed as a parameter on the command line, the child process will output 8, 4, 2, 1. Because the parent and child processes have their own copies of the data, it will be necessary for the child to output the sequence. Have the parent invoke the wait() call to wait for the child process to complete before exiting the program. Perform necessary error checking to ensure that a positive integer is passed on the command line.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91987921
  • Price:- $60

Guranteed 36 Hours Delivery, In Price:- $60

Have any Question?


Related Questions in Computer Engineering

Enter probability as a fraction or as a decimal rounded to

Enter probability as a fraction or as a decimal rounded to nearest thousandth (three A basket contains six red and four blue marbles. Three marbles are drawn at random without replacement. (WITHOUT using combinations) de ...

The second array programming assignment is from 474-483

The SECOND array programming assignment is from 474-483 Write an ArrayList program that: 1. Creates a list of 5 automobile names that you make up and then retrieves those 5 names and displays all of them. 2. Adds Mercede ...

1 what is the boolean expression for an and gate2 what is

1. What is the Boolean expression for an AND gate? 2. What is the Boolean expression for an OR gate? 3. What is the Boolean expression for a NOT gate?

What is the difference between dekkers algorithm and igloo

What is the difference between Dekkers Algorithm and Igloo approach? Please provide examples that can explain this.

Question you are to write a report on the malware assigned

Question: You are to write a report on the malware assigned to you in the "Week 6 Malware assignment by individual student" document. Your report, written in Microsoft Word with 12 point type and 1 in margins, must have ...

Assignmentnbspon information systems audit and

Assignment  on Information Systems audit and controls Assignment purpose: Elaborate on the different types of control that are applied in a hospital (Preventive, detective and corrective control). Evaluate the logical an ...

Command to mail only the process id of running java program

Command to mail only the process ID of running Java program test to the email address (single line Unix)

Question suppose you have a class whose objects are very

Question : Suppose you have a class whose objects are very, very large. Briefly, describe the advantages and drawbacks of call-by-value and call-by-reference for large objects. Describe a parameter passing mechanism that ...

Explain why a u s recession that occurs as the rest of the

Explain why a U. S. recession that occurs as the rest of the world is expanding will tend to reduce the U. S. Trade deficit.

A balloon has 050 mol ar at 175 k 0997 atm and 0775 l if

A balloon has 0.50 mol Ar at 175 K, 0.997 atm and 0.775 L. If the moles are doubled and the temperature dropped to 115 K at constant pressure, what would the volume (in L) be?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As