# IPC - process synchronization & deadlock avoidance
This project is an implementation of Inter Process Communication using ```message queues``` and subsequent resource allocation and deadlock avoidance using ```Banker's algorithm``` that tests for safety , and achieving process synchronization in the multi processing environment through semaphores by implementing the ```Dining Philosopher's``` problem , written in the C language for the Linux operating system.
## Motivation
This project was built as part of the coursework for CS3003D: Operating Systems taught by the Computer Science Engineering Department, National Institute of Technology, Calicut. The aim of the project was to implement Inter process communication using ```message queues```, design and implement the ```Banker's algorithm``` and implement ```Dining Philosopher’s problem``` using semaphore.
## Requirements
vim, gvim , neovim or any text editor to implement the c code. gcc to build and compile the c code.
## Usage
The steps to implement the above mentioned objectives and test it are detailed below:
## Message Queues
A **message queue** is a linked list of messages stored within the kernel and identified by a message queue identifier.
### Files
```c
mssg1.c
mssg2.c
mssg3.c
```
### Build and compile
Run the following commands to build and compile the files to implement message queues.
```bash
gcc mssg1.c -o mssg1
gcc mssg2.c -o mssg2
gcc mssg3.c -o mssg3
```
.
### Run
Run the following commands in three separate terminals to run the 3 programs.
```bash
./mssg3
./mssg2
./mssg1
```
## Banker's Algorithm
The **banker’s algorithm** is a resource allocation and deadlock avoidance algorithm that tests for safety by simulating the allocation for predetermined maximum possible amounts of all resources.
### Files
```c
bankers.c // Source code for Banker's algorithm
input1
input2
// Input text files To read number of
//processes, resources, AllocTable, MaxTable,
//and the total number of instances per resource type
```
### Build and Compile
Run the following commands to build and compile the files.
```bash
gcc bankers.c -o bankers
```
### Run
Run the program using the following command.
```bash
./bankers
```
## Dining Philosopher’s problem
The **Dining Philosopher Problem** states that K philosophers seated around a circular table with one chopstick between each pair of philosophers. There is one chopstick between each philosopher. A philosopher may eat if he can pickup the two chopsticks adjacent to him. One chopstick may be picked up by any one of its adjacent followers but not both.
### Files
```bash
diners.c
```
### Build And Compile
Run the following commands to build and compile the files.
```bash
gcc diners.c -o diners -lpthread -lrt
```
program may compile only with C compilers with semaphore and pthread library.``` -lpthread``` & ```-lrt```command will tell the compiler to execute program with **pthread. h** and **semaphore.h** library
### Run
Run the program using the following command.
```bash
./diners.c
```
## Author
Kannan Mangalathil (kannan_b180554cs@nitc.ac.in)
## License
This software may be restributed and/or modified under the terms of the GNU General Public License, version 3 or later, as published by the Free Software Foundation.