EX: No: INTERPROCESS COMMUNICATION USING SHARED MEMORY
Aim:
To write a c program to develop an application using Inter process Communication (IPC)
using Shared Memory.
Algorithm:
1. Create the shared memory for parent process using shmget()system call.
2. Now allow the parent process to write in shared memory using shmget pointer which is return
type of shmget()
3. Now across and attach the same shared memory to the child process
4. The data in the shared memory is read by the child process using the shmdt pointer
5. Now detach and reuse the shared memory.
Result:
Thus the IPC program using shared memory has been written and executed
successfully
EX:NO: IMPLEMENTATION OF SEMAPHORE
Aim
To write a C program to implement producer consumer relationship using semaphore.
Algorithm
1. Initialize the semaphore variables mutex =1, full=0,empty=3
2. Invoke the wait() to enter into critical section and signal() is for exit section
2. The Producer will produce until buffer is full.
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
Producer produces the item
mutex=signal(mutex);
3. The Consumer will consume until the buffer is empty.
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
consumes item
x--;
mutex=signal(mutex);
4. If the Buffer is empty then the Consumer will not consume the items.
5. If the Buffer is full then the Producer will not consume the items.
6. Print the result.
Result :
Thus the implementation of producer consumer problem using semaphore has been
executed successfully
Ex:NO: BANKERS ALGORITHM FOR DEADLOCK AVOIDANCE
AIM:
To implement Bankers Algorithm for Deadlock Avoidance using c
ALGORITHM:
1. Start the program.
2. Create a structure for all vectors
3. Get the number of resources and processes.
4. Get the avail value, allocation and max value for all processes based on each resources
5. Find the need value using max allocation
6. Check whether its possible to allocate.
7. If it is possible then the system is in safe state.
8. Else system is not in safety state.
9. If the new request comes then check that the system is in safety. or not if we allow the
request.
10. stop the program.
Result:
Thus the bankers algorithm for deadlock avoidance has been written and executed successfully
EX:NO: DEADLOCK DETECTION ALGORITHM
AIM:
To implement Bankers Algorithm for Deadlock Avoidance using C
ALGORITHM:
1. Mark each process that has a row in the Allocation matrix of all zeros.
2. Initialize a temporary vector W to equal the Available vector.
3. Find an index i such that process i is currently unmarked and the row of Q
is less than or equal to W . That is,Q ik … Wk, for 1 … k … m . If no such row is found,
terminate the algorithm.
4. If such a row is found, mark process i and add the corresponding row of the allocation matrix
to W . That is, set Wk = Wk + Aik, for 1 … k … m . Return to step 3.
Result:
Thus the deadlock detection algorithm has been written and executed successfully
[Link]: Dynamic Storage Allocation-First Fit
Aim:
To write a ‘C’ program in UNIX to implement Dynamic Storage Allocation Strategy for First
Fit.
Algorithm:
1. Start
2. Read the number of free blocks and the size of each free block.
3. Get the process block size to be loaded.
4. Allocate the first hole that is big enough to load the process
5. If no hole is big enough to load the process, then process cannot be allocated.
6. Display the size of all the free blocks.
7. Stop.
RESULT:
Thus the dynamic storage allocation scheme using firstfit algorithm has been written and
executed successfully
[Link] : Dynamic Storage Allocation-Best Fit
Aim:
To write a ‘C’ program in UNIX to implement Dynamic Storage Allocation Strategy for Best Fit.
Algorithm:
1. Start
2. Read the number of free blocks and the size of each free block.
3. Get the process block size to be loaded.
4. Allocate the smallest hole that is big enough to load the process
5. If no hole is big enough to load the process, then process cannot be allocated.
6. Display the size of all the free blocks.
7. Stop.
RESULT:
Thus the dynamic storage allocation scheme using bestfit algorithm has been written and
executed successfully
Ex. No: DYNAMIC STORAGE ALLOCATION-WORST FIT
Aim:
To write a ‘C’ program in UNIX to implement Dynamic Storage Allocation Strategy for Worst
Fit.
Algorithm:
1. Start
2. Read the number of free blocks and the size of each free block.
3. Get the process block size to be loaded.
4. Allocate the largest hole that is big enough to load the process
5. If no hole is big enough to load the process, then process cannot be allocated.
6. Display the size of all the free blocks.
7. Stop.
RESULT:
Thus the dynamic storage allocation scheme using worstfit algorithm has been written and
executed successfully