Semaphores are used to mediate access to computer resources. Your task is to write a program that uses semaphores to simulate mediated access to three computer resources: 5 printers 6 plotters 4 scanners   Your program shall: Declare and initialize the semaphores with the appropriate values. Create a routine that loops through a sequence 4 times. In each iteration the process forks a child process. The child process: uses a random number generator (1-3) to determine which resource it will request uses native semaphore function or one that you create to request the appropriate resource Print the process’ PID and the requested resource type Print the process’ PID and the success/failure of the request if the resource is available - sleep for a random time between 1-3 seconds and then release the resource using appropriate the semaphore function if the resource is not available – sleep for a random between 2-4 seconds and repeat the request (go to step ii). Terminate Sleeps for a random time between 1-3 seconds

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

IN C++:

Semaphores are used to mediate access to computer resources.

Your task is to write a program that uses semaphores to simulate mediated access to three computer resources:

  1. 5 printers
  2. 6 plotters
  3. 4 scanners

 

Your program shall:

  1. Declare and initialize the semaphores with the appropriate values.
  2. Create a routine that loops through a sequence 4 times. In each iteration the process
    1. forks a child process.
      The child process:
      1. uses a random number generator (1-3) to determine which resource it will request
      2. uses native semaphore function or one that you create to request the appropriate resource
      3. Print the process’ PID and the requested resource type
      4. Print the process’ PID and the success/failure of the request
      5. if the resource is available - sleep for a random time between 1-3 seconds and then release the resource using appropriate the semaphore function
      6. if the resource is not available – sleep for a random between 2-4 seconds and repeat the request (go to step ii).
      7. Terminate
    2. Sleeps for a random time between 1-3 seconds
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY