0% found this document useful (0 votes)
11 views20 pages

OS - 1 To 8

Uploaded by

coveredthomas321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views20 pages

OS - 1 To 8

Uploaded by

coveredthomas321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

JSS Academy of Technical Education Noida Department of Information Technology

EXPERIMENT No. - 1

Aim- Perform the Comparative Analysis of different Operating System.

Linux Mac UNIX Android iOS


Linux is Apple Inc. Three biggest Open Apple Inc.
Manufactur Microsoft developed as for their distributions are source closed, with
er Inc. open source OS Macintosh Solaris OS components
under line of running designed that are
the GNU project computer (Oracle), &develop source openly
by systems. AIXon (IBM) & ed
the Originator, by
Linus Android
Torvalds and Inc.
many Google is
others. now the
current
owner

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)

Target Workstation, Desktop/Server Workstati 8086 UNIX Consumer Smartphone,


System Personal Depends on on, system, , music system
Type Computer, Distribution Personal PDP-11/70 Enterprise player, Tablet
Media Computer, system , system/compu
Centre, embedded education ter
Tablet PC,
Embedded.

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

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

9660; UDF, NFS, and


rd and others before)
3 AFP,
Party driver with ISO
that 9660,
supports file FAT,
system UDF
ext2, and
ext3,
ReiserFS,
and HFS

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

Integrate Windows Chroot Ap pli ca tio IPFilter iptables Firewall-IP


Firewall capability- n for iOS
d based security, Firewall
Firewall [s 5]
seccomp,
SELinux

Security Huge Negligible Negligible Mild Negligibl Negligible


Threats e

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.

Kernel Hybrid Monolithic Monolithi Monolithic with Linux XNU kernel;


Type with c modules kernel of Darwin
modules with
modules

Reliability Great Great Greatest Greater Could be More than


unstable Android

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

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

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

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

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");

for (i = 0; i < n; i++) {


printf("P%d: ", i + 1);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
}
for (i = 0; i < n; i++) {
index = i;
for (j = i + 1; j < n; j++)
if (A[j][1] < A[index][1])

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");

for (i = 0; i < n; i++) {


A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
printf("P%d %d %d %d\n", A[i][0],
} A[i][1], A[i][2], A[i][3]);
avg_tat = (float)total / n;
printf("Average Waiting Time= %f", avg_wt);
printf("\nAverage Turnaround Time= %f", avg_tat);
}
OUTPUT:
Enter number of process: 3
Enter Burst Time:
P2: 5
P1: 10 P3: 8
P BT WT TAT
P2 5 0 5
P3 8 5 13
P1 10 13 23
Average Waiting Time= 6.000000
Average Turnaround Time= 13.666667

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

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("Enter the number of processes: ");


scanf("%d", &n);
for (int i = 0; i < n; i++)
{
printf("Enter arrival time and burst time for process %d: ", i+1);
scanf("%d %d", &processes[i].arrival_time, &processes[i].burst_time);
processes[i].pid = i+1;
processes[i].remaining_time = processes[i].burst_time;
}

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;
}

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

printf("Process\tArrival Time\tBurst Time\tWaiting Time\tTurnAround Time\n");

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:

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

EXPERIMENT No. 5
Aim-Write a program to implement Round Robin algorithm (RR)

Source Code:
#include <iostream>
using namespace std;

void queueUpdation(int queue[],int timer,int arrival[],int n, int maxProccessIndex){

int zeroIndex;

for(int i = 0; i < n; i++){

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++){

int temp = queue[i];

queue[i] = queue[i+1];

queue[i+1] = temp;

void checkNewArrival(int timer, int arrival[], int n, int maxProccessIndex,int queue[]){

if(timer <= arrival[n-1]){

bool newArrival = false;

for(int j = (maxProccessIndex+1); j < n; j++){

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

if(arrival[j] <= timer){

if(maxProccessIndex < j){

maxProccessIndex = j;

newArrival = true;

queueUpdation(queue,timer,arrival,n, maxProccessIndex);
}

int main(){

int n,tq, timer = 0, maxProccessIndex = 0;

float avgWait = 0, avgTT = 0;

cout << "\nEnter the time quanta : ";

cin>>tq;
cout << "\nEnter the number of processes : ";

cin>>n;

int arrival[n], burst[n], wait[n], turn[n], queue[n], temp_burst[n];

bool complete[n];

cout << "\nEnter the arrival time of the processes : ";

for(int i = 0; i < n; i++)

cin>>arrival[i];

cout << "\nEnter the burst time of the processes : ";

for(int i = 0; i < n; i++){

cin>>burst[i];

temp_burst[i] = burst[i];

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

for(int i = 0; i < n; i++){ //Initializing the queue and complete array

complete[i] = false;

queue[i] = 0;

while(timer < arrival[0]) //Incrementing Timer until the first process arrives

timer++;

queue[0] = 1;

while(true){

bool flag = true;

for(int i = 0; i < n; i++){

if(temp_burst[i] != 0){

flag = false;

break;

}
}

if(flag)

break;

for(int i = 0; (i < n) && (queue[i] != 0); i++){

int ctr = 0;

while((ctr < tq) && (temp_burst[queue[0]-1] > 0)){

temp_burst[queue[0]-1] -= 1;

timer += 1;

ctr++;

//Checking and Updating the ready queue until all the processes arrive

checkNewArrival(timer, arrival, n, maxProccessIndex, queue);

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

}
}
//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;
}
}
}

for(int i =0; i< n; i++){

avgWait += wait[i];

avgTT += turn[i];

cout<<"\nAverage wait time : "<<(avgWait/n)

<<"\nAverage Turn Around Time : "<<(avgTT/n);

return 0;

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

OUTPUT :
Enter the time quanta : 2

Enter the number of processes : 4

Enter the arrival time of the processes : 0 1 2 3

Enter the burst time of the processes : 5 4 2 1

Program No. Arrival Time 0 Burst Time Wait Time TAT


1234 123 5 7 12
4 6 10
2 2 46
1 5
Average wait time : 5
Average Turn Around Time : 8

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

EXPERIMENT -6
Aim-Write a program to implement Priority based scheduling

Source Code:

#include<stdio.h>

#include<stdlib.h>

struct process {

int process_id; int

burst_time; int

priority; int

waiting_time; int

turnaround_time;

};

void find_waiting_time(struct process[], int, int[]);

void find_turnaround_time(struct process[], int, int[], int[]);

void find_average_time(struct process[], int);

void priority_scheduling(struct process[], int);

int main()

{ intn,i;

struct process proc[10];

printf("Enter the number of processes: ");

scanf("%d", &n);

for(i = 0; i< n; i++)

{ printf("\nEntertheprocessID:");

scanf("%d", &proc[i].process_id);

printf("Enter the burst time: ");

scanf("%d", &proc[i].burst_time);

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

printf("Enter the priority: ");

scanf("%d", &proc[i].priority); }

priority_scheduling(proc, n);

return 0; }

void find_waiting_time(struct process proc[], int n, int wt[])

{ inti;

wt[0] = 0;

for(i = 1; i< n; i++)

wt[i] = proc[i - 1].burst_time + wt[i - 1];

} }

void find_turnaround_time(struct process proc[], int n, int wt[], int tat[])

int i;

for(i = 0; i< n; i++)

tat[i] = proc[i].burst_time + wt[i];

}}

void find_average_time(struct process proc[], int n)

{ int wt[10], tat[10], total_wt = 0, total_tat = 0, i;

find_waiting_time(proc, n, wt);

find_turnaround_time(proc, n, wt, tat);

printf("\nProcess ID\tBurst Time\tPriority\tWaiting Time\tTurnaround Time");

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

for(i = 0; i< n; i++)

{ total_wt = total_wt + wt[i];

total_tat = total_tat + tat[i];

printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", proc[i].process_id, proc[i].burst_time, proc[i].priority, wt[i],


tat[i]); }

printf("\n\nAverage Waiting Time = %f", (float)total_wtotal_wt/n);

printf("\nAverage Turnaround Time = %f\n", (float)total_tat/n);

void priority_scheduling(struct process proc[], int n)

{ int i, j, pos;

struct process temp;

for(i = 0; i< n; i++)

{ pos=i;

for(j = i + 1; j < n; j++)

if(proc[j].priority< proc[pos].priority)

pos = j; }

temp = proc[i];

proc[i] = proc[pos];

proc[pos] = temp;

find_average_time(proc, n);

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

OUTPUT

Enter the number of processes: 3

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

Process ID Burst Time Priority Waiting Time Turnaround Time 2 2 1 0 2 1 5 2 2 7 3 4 3 7

11

Average Waiting Time = 3.000000

Average Turnaround Time = 6.666667

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

EXPERIMENT -7

Aim-Write a program to implement Bankers algorithm in C++/C

Source Code:
#include<iostream>
using namespace std;
const int P = 5;
const int R = 3;

void calculateNeed(int need[P][R], int maxm[P][R],


int allot[P][R])
{
for (int i = 0 ; i < P ; i++)
for (int j = 0 ; j < R ; j++)
need[i][j] = maxm[i][j] - allot[i][j];
}

bool isSafe(int processes[], int avail[], int maxm[][R],


int allot[][R])
{
int need[P][R];
calculateNeed(need, maxm, allot);
bool finish[P] = {0};
int safeSeq[P];
int work[R];
for (int i = 0; i < R ; i++)
work[i] = avail[i];

int count = 0;
while (count < P)
{
bool found = false;
for (int p = 0; p < P; p++)
{
if (finish[p] == 0)
{

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

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;
}

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

OUTPUT

System is in safe state.

Safe sequence is: 1 3 4 0 2

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

EXPERIMENT -8

Aim-Write a program to implement First Fit algorithm of memory allocation in C++/C

Source Code:

#include<iostream>
using namespace std;

int main()
{
int bsize[10], psize[10], bno, pno, flags[10], allocation[10], i, j;

for(i = 0; i < 10; i++)


{
flags[i] = 0;
allocation[i] = -1;
}

cout<<"Enter no. of blocks: ";


cin>>bno;

cout<<"\nEnter size of each block: ";


for(i = 0; i < bno; i++)
cin>>bsize[i];

cout<<"\nEnter no. of processes: ";


cin>>pno;

cout<<"\nEnter size of each process: ";


for(i = 0; i < pno; i++)
cin>>psize[i];
for(i = 0; i < pno; i++) //allocation as per first fit
for(j = 0; j < bno; j++)
if(flags[j] == 0 && bsize[j] >= psize[i])
{
allocation[j] = i;
flags[j] = 1;
break;
}

OS lab Pulak Jakhmola 2200910130135


JSS Academy of Technical Education Noida Department of Information Technology

//display allocation details


cout<<"\nBlock no.\tsize\t\tprocess no.\t\tsize";
for(i = 0; i < bno; i++)
{
cout<<"\n"<< i+1<<"\t\t"<<bsize[i]<<"\t\t";
if(flags[i] == 1)
cout<<allocation[i]+1<<"\t\t\t"<<psize[allocation[i]];
else
cout<<"Not allocated";
}

return 0;
}

OUTPUT

Enter no. of blocks: 5

Enter size of each block: 50 100 150 200 250

Enter no. of processes: 4

Enter size of each process: 50 200 125 100

Block no. size process no. size

1 50 1 50

2 100 4 100

3 150 3 125

4 200 2 200

5 250 Not allocated

OS lab Pulak Jakhmola 2200910130135

You might also like