Giter Site home page Giter Site logo

dining-philosophers's Introduction

Dining Philosophers Problem using Network Calls in Distributed Systems


This program demonstrates a solution to Dining Philosophers's Problem using Network Calls as the only means of communication.

What is Dining Philosopher Problem?

Five philosophers, live in a house and dine at the same table. Each philosopher has their own place at the table. Their only problem aside from those of philosophy, is that the dish served is a kind of spaghetti, that has to be eaten with two forks. There is a fork between each plate.

Each philosopher will alternately think and eat. However, a philosopher can only eat the spaghetti when they have both a left and right fork. Two forks will only be available when their two nearest neighbors are thinking, not eating. After an individual philosopher finishes eating, they will put down both forks.

The problem is how to design a discipline of behavior (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think.

Read more about the problem from this Wikipedia article.

Program Description

a. Create five child processes for philosophers, and five child processes for each of the chopsticks.

b. Initiate a pair of sockets for each connection to a server

c. Avoid possible deadlock

d. Close and unlink the sockets.

Description: Use the fork() system call to create a child process. The parent should do nothing but create ten child processes. The requests for granting and releasing chopsticks should be done by each child process representing a philosopher through communication with the two processes representing the philosopher’s left and right hand chopsticks.TCP/IP should be used for communication between philosophers and chopstick processes. The datagram type of sockets should be employed between the parent and child processes including both the philosopher and chopstick processes. Use write() and read() system calls with the connection-oriented communication. A solution that prevents deadlock or starvation should be implemented. For example the RightLeftDP algorithm (Lynch,1996) is a suitable algorithm. Five child processes are to be created for the five philosophers. The philosophers change their states among “thinking”, “waiting”, and “eating” until all philosophers fulfil their eating requirements(60 seconds total eating time). Print the status of each philosopher whenever there is a change in the status.

Requirements

gcc

Running the Program

$ gcc main.c

Acknowledgement

I would like to thank Jini Raju for assigning this project to me.

dining-philosophers's People

Contributors

niranjanneeru avatar

Stargazers

 avatar Akshay K avatar Eason Wang avatar Sreelakshmi Satheesh avatar  avatar Shana avatar Sreelekshmi N S avatar  avatar Angath J R avatar Jishnu Das  avatar Alex Joseph Pius avatar Muhammed avatar Muhammed Mizaj avatar Almira Asif Khan avatar Fathima Nooha  avatar  avatar ASHWIN BINU ABRAHAM avatar Asher Mathews Shaji avatar Asher Mathews  avatar Meenakshy Balakrishnan avatar  avatar Laveena Herman avatar  avatar

Watchers

 avatar

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.