Giter Club home page Giter Club logo

bankers-algorithm-operating-system-assignment's Introduction

Bankers Algorithm

Assignment

Operating Systems

Question

Write a multithreaded program that implements the banker's algorithm. Create n threads that request and release resources from the bank. The banker will grant the request only if it leaves the system in a safe state. It is important that shared data be safe from concurrent access. To ensure safe access to shared data, you can use mutex locks.

Solution

Compile Manually

# compile
gcc bankers_algorithm.c -std=c99 -pthread -o bankers_algorithm

# execute
./bankers_algorithm

Input

Number of processes? 5
Number of resources? 3

Currently Available resources (R1 R2 ...)? 3 3 2

Resource allocated to process 1 (R1 R2 ...)? 0 1 0
Resource allocated to process 2 (R1 R2 ...)? 2 0 0
Resource allocated to process 3 (R1 R2 ...)? 3 0 2
Resource allocated to process 4 (R1 R2 ...)? 2 1 1
Resource allocated to process 5 (R1 R2 ...)? 0 0 2

Maximum resource required by process 1 (R1 R2 ...)? 7 5 3
Maximum resource required by process 2 (R1 R2 ...)? 3 2 2
Maximum resource required by process 3 (R1 R2 ...)? 9 0 2
Maximum resource required by process 4 (R1 R2 ...)? 2 2 2
Maximum resource required by process 5 (R1 R2 ...)? 4 3 3

Output

Safe Sequence Found : 2  4  5  1  3
Executing Processes...


--> Process 2
	Allocated :   2  0  0
	Needed    :   1  2  2
	Available :   3  3  2
	Resource Allocated!
	Process Code Running...
	Process Code Completed...
	Process Releasing Resource...
	Resource Released!
	Now Available :   5  3  2


--> Process 4
	Allocated :   2  1  1
	Needed    :   0  1  1
	Available :   5  3  2
	Resource Allocated!
	Process Code Running...
	Process Code Completed...
	Process Releasing Resource...
	Resource Released!
	Now Available :   7  4  3


--> Process 5
	Allocated :   0  0  2
	Needed    :   4  3  1
	Available :   7  4  3
	Resource Allocated!
	Process Code Running...
	Process Code Completed...
	Process Releasing Resource...
	Resource Released!
	Now Available :   7  4  5


--> Process 1
	Allocated :   0  1  0
	Needed    :   7  4  3
	Available :   7  4  5
	Resource Allocated!
	Process Code Running...
	Process Code Completed...
	Process Releasing Resource...
	Resource Released!
	Now Available :   7  5  5


--> Process 3
	Allocated :   3  0  2
	Needed    :   6  0  0
	Available :   7  5  5
	Resource Allocated!
	Process Code Running...
	Process Code Completed...
	Process Releasing Resource...
	Resource Released!
	Now Available :  10  5  7


All Processes Finished

TODO

  • Makefile

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.