OS - 1 To 8
OS - 1 To 8
EXPERIMENT No. - 1
Developmen Developed Linux is Open Mac OS Unix system has OHA Apple Inc.
t and and Sourced and was various flavors, (Open developed
Distribution distributed by distributed by designed most of Handset and
Microsoft. various only to be which are Alliance) distributed
vendors. deployed developed by iOS
by AT&T with
Apple other
Computers commercial
. vendors
and non-profit
orgs
Computer x86, x86-64 x86, x86-64, 68k, Available on PA- Android- ARM
Architecture PowerPC, PowerPC RISC x86
Supported SPARC, and Itanium powered
Alpha, Others machines. by
Solaris also AMD and
available Intelx86
for x86/x64 processor
based s
systems. OSX is
PowerPC(10.0-
10.5)/x86(10.4)/
x64
(10.5-10.8)
File NTFS, FAT ext2, ext3, HFS+, jfs, gpfs, hfs, Ext4 HFS+, FTP
System & ex4,ReiserFS,F HFS, hfs+, ufs,
Supported exFAT with AT, MFS (Mac xfs, zfs format
ISO ISO 9660,UDF, OS 8.0
User Very User Depends on Very User Unix is user- Very User Very User
Friendly Friendly Distribution. Friendly friendly. Friendly Friendly
for Lay More It's just choosy
Users friendlier to about
users
Shell CMD Bash shell BASH Originally the Mosh Blink Shell
Terminal powerful Bourne
shell with Shell. Now it's
many compatible with
features many
others including
BASH,
Korn & C.
Compatibilit Can coexist on Linux has Only few Unix does not Better Compatibility
y local networks few programs have as much than is fair
with Windows, programs and will run on compatibility iOS
BSD, Macs, and games mac when it
other Unix-like like comes to
systems. More Windows. games and
compatible. But is software
more
compatible
and
scalable than
Unix
EXPERIMENT No. 2
Aim- To implement the functioning of FCFS (first come first serve)
Source Code:
#include<stdio.h>
void findWaitingTime(int processes[], int n, int bt[], int wt[])
{
wt[0] = 0;
for (int i = 1; i < n ; i++ )
wt[i] = bt[i-1] + wt[i-1] ;
}
void findTurnAroundTime( int processes[],int n, int bt[], int wt[])
{
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}
void findavgTime( int processes[], int n, int bt[])
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt);
findTurnAroundTime(processes, n, bt, wt, tat);
printf("Processes BurstTime WaitingTime TurnAroundTime\n");
for (int i=0; i<n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
printf(" %d ",(i+1));
printf(" %d ", bt[i] );
printf(" %d",wt[i] );
printf(" %d\n",tat[i] );
}
float s=(float)total_wt / (float)n;
float t=(float)total_tat / (float)n;
printf("Average waiting time = %f",s);
printf("\n");
printf("Average turn around time = %f ",t);
}
int main()
{int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];
int burst_time[] = {10, 5, 8};
findavgTime(processes, n, burst_time);
return 0; }
OUTPUT:
Processes BurstTime WaitingTime TurnAroundTime
1 10 0 10
2 5 10 15
3 8 15 23
Average waiting time = 8.333333
Average turn around time = 16.000000
EXPERIMENT No. 3
Aim-Write a program to implement Shortest Job First (SJF)
Source Code:
#include <stdio.h>
int main()
{
int A[100][4];
int i, j, n, total = 0, index, temp;
float avg_wt, avg_tat;
printf("Enter number of process: ");
scanf("%d", &n);
printf("Enter Burst Time:\n");
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
for (i = 1; i < n; i++) {
A[i][2] = 0;
for (j = 0; j < i; j++)
A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
printf("P BT WT TAT\n");
EXPERIMENT No. 4
Aim-Write a program to implement Shortest Time Remaining Next (STRN)
Source Code:
#include <stdio.h>
#include <stdbool.h>
#define MAX_PROCESSES 100
struct process {
int pid;
int arrival_time;
int burst_time;
int remaining_time;
};
int main() {
int n;
struct process processes[MAX_PROCESSES];
bool completed[MAX_PROCESSES] = {false};
int current_time = 0;
int shortest_time = 0;
int shortest_index = 0;
printf("\n");
while (true) {
bool completed_all = true;
for (int i = 0; i < n; i++) {
if (!completed[i]) {
if (processes[i].arrival_time <= current_time &&processes[i].remaining_time < processes[shortest_index].
remaining_timeshortest_index =i; }
}
}
if (completed_all) { break;
}
if (shortest_index != -1) {
processes[shortest_index].remaining_time--; if (processes[shortest_index].remaining_time ==
0) { completed[shortest_index] = true; }
}
current_time++;
shortest_index = -1;
}
int total_waiting_time = 0;
int total_turnaround_time = 0;
for (int i = 0; i < n; i++) {
int waiting_time = 0;
int turnaround_time = 0; waiting_time = current_time - processes[i].burst_time -
processes[i].arrival_time;
turnaround_time = current_time - processes[i].arrival_time;
total_waiting_time += waiting_time;
total_turnaround_time += turnaround_time;
printf("%d\t%d\t\t%d\t\t%d\t\t%d\n", processes[i].pid, processes[i].arrival_time,
processes[i].burst_time, waiting_time, turnaround_time);
}
float avg_waiting_time = (float) total_waiting_time / n;
float avg_turnaround_time = (float) total_turnaround_time / n;
printf("The Average Waiting Time: %.2f\n", avg_waiting_time);
printf("The Average Turnaround Time: %.2f\n", avg_turnaround_time);
return 0;
}
OUTPUT:
EXPERIMENT No. 5
Aim-Write a program to implement Round Robin algorithm (RR)
Source Code:
#include <iostream>
using namespace std;
int zeroIndex;
if(queue[i] == 0){
zeroIndex = i;
break;
} }
} }
}queue[zeroIndex] = maxProccessIndex + 1;
}
queueUpdation(queue,timer,arrival,n, maxProccessIndex);
}
void queueMaintainence(int queue[], int n){
}
for(int i = 0; (i < n-1) && (queue[i+1] != 0) ; i++){
queue[i] = queue[i+1];
queue[i+1] = temp;
maxProccessIndex = j;
newArrival = true;
queueUpdation(queue,timer,arrival,n, maxProccessIndex);
}
int main(){
cin>>tq;
cout << "\nEnter the number of processes : ";
cin>>n;
bool complete[n];
cin>>arrival[i];
cin>>burst[i];
temp_burst[i] = burst[i];
complete[i] = false;
queue[i] = 0;
while(timer < arrival[0]) //Incrementing Timer until the first process arrives
timer++;
queue[0] = 1;
while(true){
if(temp_burst[i] != 0){
flag = false;
break;
}
}
if(flag)
break;
int ctr = 0;
temp_burst[queue[0]-1] -= 1;
timer += 1;
ctr++;
//Checking and Updating the ready queue until all the processes arrive
}
}
//If a process is completed then store its exit time
}
//and mark it as completed
else
if((temp_burst[queue[0]-1] == 0) && (complete[queue[0]-1] == false)){
idle = false;
//turn array currently stores the completion time
turn[queue[0]-1] = timer;
if(idle){
complete[queue[0]-1] = true;
timer++;
}
checkNewArrival(timer, arrival, n, maxProccessIndex, queue);
//checks whether or not CPU is idle
}
bool idle = true;
if(queue[n-1] == 0){
//Maintaining the entries of processes
for(int i = 0; i < n && queue[i] != 0; i++){
//after each premption in the ready Queue
if(complete[queue[i]-1] == false){
queueMaintainence(queue,n);
idle = false;
}
}
}
avgWait += wait[i];
avgTT += turn[i];
return 0;
OUTPUT :
Enter the time quanta : 2
EXPERIMENT -6
Aim-Write a program to implement Priority based scheduling
Source Code:
#include<stdio.h>
#include<stdlib.h>
struct process {
burst_time; int
priority; int
waiting_time; int
turnaround_time;
};
int main()
{ intn,i;
scanf("%d", &n);
{ printf("\nEntertheprocessID:");
scanf("%d", &proc[i].process_id);
scanf("%d", &proc[i].burst_time);
scanf("%d", &proc[i].priority); }
priority_scheduling(proc, n);
return 0; }
{ inti;
wt[0] = 0;
} }
int i;
}}
find_waiting_time(proc, n, wt);
{ int i, j, pos;
{ pos=i;
if(proc[j].priority< proc[pos].priority)
pos = j; }
temp = proc[i];
proc[i] = proc[pos];
proc[pos] = temp;
find_average_time(proc, n);
OUTPUT
Enter the process ID: 1 Enter the burst time: 5 Enter the priority: 2
Enter the process ID: 2 Enter the burst time: 2 Enter the priority: 1
Enter the process ID: 3 Enter the burst time: 4 Enter the priority: 3
11
EXPERIMENT -7
Source Code:
#include<iostream>
using namespace std;
const int P = 5;
const int R = 3;
int count = 0;
while (count < P)
{
bool found = false;
for (int p = 0; p < P; p++)
{
if (finish[p] == 0)
{
int j;
for (j = 0; j < R; j++)
if (need[p][j] > work[j])
break;
if (j == R){
for (int k = 0 ; k < R ; k++)
work[k] += allot[p][k];
safeSeq[count++] = p;
finish[p] = 1;
}
if (found == false)
{ cout << "System is not in safe state";
return false;
}
cout << "System is in safe state.\nSafe"
" sequence is: ";
for (int i = 0; i < P ; i++)
cout << safeSeq[i] << " ";
return true;
}
int main(){
int processes[] = {0, 1, 2, 3, 4};
int avail[] = {3, 3, 2};
int maxm[][R] = {{7, 5, 3},
{3, 2, 2},
{9, 0, 2},
{2, 2, 2},
{4, 3, 3}};
int allot[][R] = {{0, 1, 0},
{2, 0, 0},
{3, 0, 2},
{2, 1, 1},
{0, 0, 2}};
isSafe(processes, avail, maxm, allot);
return 0;
}
OUTPUT
EXPERIMENT -8
Source Code:
#include<iostream>
using namespace std;
int main()
{
int bsize[10], psize[10], bno, pno, flags[10], allocation[10], i, j;
return 0;
}
OUTPUT
1 50 1 50
2 100 4 100
3 150 3 125
4 200 2 200