Create the child process and wait for it to terminate

Assignment Help Basic Computer Science
Reference no: EM131232028

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.

Reference no: EM131232028

Questions Cloud

Write a program that implements the fifo and lru : Implement the replacement algorithms so that the number of page frames can vary from 1 to 7. Assume that demand paging is used.
Improve productivity and patient satisfaction : What would the president and medical director want to know before making any financial and organizational decisions - develop recommendations to improve productivity and patient satisfaction.
Define what each of these constructs means : Tannen points out that a common communication strategy is to convey intended messages indirectly. What points does she make about this? Why do people convey messages indirectly? What are its advantages? What are its disadvantages? Illustrate your ..
Describe current status in your leadership development : Leadership is creativity in action. It is the ability to see the present in terms of the future while maintaining respect for the past. Based on the above definition, describe for me your current status in your leadership development.
Create the child process and wait for it to terminate : 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 ..
Evaluate the role of ethical decision-making in business : Discuss the key countries that might be associated with the risk. Evaluate the role of ethical decision-making in business organizations. Analyze the impact of business ethics on stakeholder relationships.
Find the total return over the 36-month period : FIN 132 - Efficient Frontier (Risk and Return) - Find the total return over the 36-month period for each stock. Which stock had the highest and lowest returns? Was this expected? Are these results consistent with the general risk-return relationshi..
Design the wl ratios of the transistors : Design the W/L ratios of the transistors to provide symmetrical switching times equal to the basic CMOS inverter with (W/L)n = 2 and (W/L)p = 4.
Describe the negative impact the project would face : Identify at least four significant team communication challenges she would be facing on this project that would be tied to the fact that she was working with a virtual team. Explain carefully the problems associated with each challenge.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd