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
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...
Related questions
Question
IN C++:
Semaphores are used to mediate access to computer resources.
Your task is to write a
- 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
- forks a child process.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Recommended textbooks for you
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY