OS Lab Manual
OS Lab Manual
List of Experiments
Practical Name of Experiment Planned Dates of Signature of
Number Date Actual Faculty
Conduction
1 Write a program to implement FCFS CPU
Scheduling algorithm.
Algorithm:
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Set the waiting of the first process as ‘0’ and its burst time as its turnaround time
a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
b) Turnaround time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):");
scanf("%d",&n);
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);
return 0;
}
Algorithm:
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest to
Step 5: Set the waiting time of the first process as ‘0’ and its turnaround time as its burst time.
a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
b) Turnaround time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
void main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
OUTPUT
Algorithm:
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 5: Set the waiting of the first process as ‘0’ and its burst time as its turnaround time
a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
b) Turnaround time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 7: Calculate
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);
//sorting burst time, priority and process number in ascending order using selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
total+=wt[i];
}
return 0;
}
OUTPUT
Algorithm:
Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Calculate the no. of time slices for each process where
No. of time slice for process (n) = burst time process (n)/time slice
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
a) Waiting time for process(n) = waiting time of process(n-1)+ burst time of process(n-1 ) +
b) Turnaround time for process(n) = waiting time of process(n) + burst time of process(n)+
Step 7: Calculate
Avg_TAT=total_tat/n;
Avg_WT=total_wt/n;
OUTPUT
Algorithm:
Mutex initialized to 0 which allows only one process to execute at any time.
4. The reader process, checks if any process is writing. If so it waits else it reads the content
5. The Writer process checks if any other process is accessing the shared variable. If not it
PROGRAM
OUTPUT
Algorithm:
2. Declare three semaphore variable mutex and a shared variable which is used by reader
4. The reader process, checks if any process is writing. If so it waits else it reads the content
5. The Writer process checks if any other process is accessing the shared variable. If not it
PROGRAM
OUTPUT
Algorithm:
PROGRAM
OUTPUT
Algorithm:
Step 2: When the page is required replace the page at the head of the queue
Step 3: Now the new page is inserted at the tail of the queue
Step 5: When the page fault occurs replace page present at the bottom of the stack
PROGRAM
OUTPUT
Algorithm:
Step 2: When the page is required replace the page at the head of the queue
Step 3: Now the new page is inserted at the tail of the queue
PROGRAM
OUTPUT
AIM: To implement page replacement algorithms Optimal (The page which is not used for
longest time).
Algorithm:
Step 2: When the page fault occurs replace page that will not be used for the longest
Period of time
PROGRAM
OUTPUT
Algorithm:
Step 3: Enter the number of processes and their sizes for process creation.
Step 4: Compare the process and size then the process is successfully to allocate given hole.
Step 5: In best-fit memory management scheme allocates the smallest hole that is big enough.
OUTPUT
Algorithm:
Step 3: Enter the number of processes and their sizes for process creation.
Step 4: Compare the process and size then the process is successfully to allocate given hole.
Step 5: In worst fit memory management scheme the biggest hole is allocated.
PROGRAM
OUTPUT
Algorithm:
Step 4: Enter the number of processes and their sizes for process creation.
Step 5: Compare the process and size then the process is successfully to allocate given hole.
Step 6: In first fit memory management scheme the first biggest hole is allocated first.
PROGRAM
OUTPUT
Banker’s Algorithm- When a new process enters a system, it must declare the maximum
number of instances of each resource type it needed. This number may exceed the total number
of resources in the system. When the user requests a set of resources, the system must determine,
whether the allocation of each resources will leave the system in safe state or not. Either the
resources will be allocated; otherwise the process must wait until some other process release the
resources.
Data structures
Need: If Need[I, j]=k, Pi may need k more instances of resource type Rj,
Safety Algorithm
1. Work and Finish be the vector of length m and n respectively, Work=Available and
Finish[i] =False.
2. Find an i such that both
3. Finish[i] =False
4. Need<=Work
3. Have the system pretend to have allocated the requested resources to process Pi by
modifying the state as follows;
Available=Available-Request I;
Allocation I =Allocation+Request I;
If the resulting resource allocation state is safe, the transaction is completed and process Pi is
allocated its resources. However, if the state is unsafe, the Pi must wait for Request (i) and the
old resource-allocation state will be restored.
Algorithm:
8. If the new request comes then check that the system is in safety.
OUTPUT
Experiment-15
Name of Experiment- Write a program to implement various Disk Scheduling
Algorithms.
Introduction- In operating systems, seek time is very important. Since all device requests are
linked in queues, the seek time is increased causing the system to slow down. Disk Scheduling
Algorithms are used to reduce the total seek time of any request.
Although there are other algorithms that reduce the seek time of all requests, I will only
concentrate on the following disk scheduling algorithms:
AIM: To write a ‘C’ program to implement the Disk Scheduling algorithm for First Come First
Served (FCFS), Shortest Seek Time First (SSTF), and SCAN.
PROBLEM DESCRIPTION:
Algorithm:
Input the maximum number of cylinders and work queue and its head starting position.
First Come First Serve Scheduling (FCFS) algorithm – The operations are performed in order
requested. There is no reordering of work queue. Every request is serviced, so there is
no starvation. The seek time is calculated.
Shortest Seek Time First Scheduling (SSTF) algorithm – This algorithm selects the request
with the minimum seek time from the current head position. Since seek time increases with the
number of cylinders traversed by the head, SSTF chooses the pending request closest to the
current head position. The seek time is calculated.
SCAN Scheduling algorithm – The disk arm starts at one end of the disk, and moves toward the
other end, servicing requests as it reaches each cylinder, until it gets to the other end of the disk.
At the other end, the direction of head movement is reversed, and servicing continues. The head
continuously scans back and forth across the disk. The seek time is calculated. Display the seek
time and terminate the program
PROGRAM
OUTPUT