0% found this document useful (0 votes)
4 views31 pages

Os File

The OS Lab Manual outlines practical exercises focused on studying five commonly used operating systems: UNIX, Linux, macOS, Windows, and Android, detailing their features and functionalities. It also includes programming exercises for calculating waiting time (WT) and turnaround time (TAT) using various CPU scheduling algorithms such as FCFS, SJF, SRTF, and Priority Scheduling. Each practical section provides code examples and expected outputs to facilitate understanding of operating system concepts.

Uploaded by

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

Os File

The OS Lab Manual outlines practical exercises focused on studying five commonly used operating systems: UNIX, Linux, macOS, Windows, and Android, detailing their features and functionalities. It also includes programming exercises for calculating waiting time (WT) and turnaround time (TAT) using various CPU scheduling algorithms such as FCFS, SJF, SRTF, and Priority Scheduling. Each practical section provides code examples and expected outputs to facilitate understanding of operating system concepts.

Uploaded by

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

OS LAB MANUAL

PRACTICAL NO. 1
Objective: Study of five most commonly used OS.

1. UNIX –
UNIX is a versatile operating system developed in the 1970s at Bell Labs. It
follows the philosophy of simplicity and modularity, offering a set of
powerful tools for various tasks. It supports multitasking and multiuser
capabilities, allowing multiple processes and users to work simultaneously.
UNIX utilizes a hierarchical file system, treating everything as files. The
command-line interface, known as the shell, enables users to interact with
the system efficiently. Networking is a core feature of UNIX, with built-in
protocols and tools for network communication. UNIX is highly portable
across different hardware architectures, contributing to its widespread
adoption. It has influenced the development of other operating systems and
has variants ranging from proprietary to open source, such as BSD and
Linux. UNIX's impact on modern computing is significant, with its design
principles remaining relevant to this day.

1. LINUX –
Linux is a popular open-source operating system that was first released
by Linus Torvalds in 1991. It is based on the UNIX operating system and
shares many of its design principles. Linux offers a stable and reliable
platform for a wide range of devices, from servers to embedded systems
and personal computers. It supports multitasking, multiuser capabilities,
and a hierarchical file system. Linux provides a highly customizable
environment with a variety of desktop environments and software
options. Its open-source nature allows users to modify and distribute the
operating system freely. Linux has a strong community of developers and
users who contribute to its ongoing development and provide support. Its
versatility, security, and cost-effectiveness have made Linux a popular

choice in various industries and among tech-savvy individuals .

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

2. MacOS –
macOS is the operating system developed by Apple Inc. for their
Macintosh computers. It is known for its sleek design, user-friendly
interface, and integration with Apple's ecosystem. macOS is built on a
Unix-based foundation and offers a stable and secure platform for
desktop and laptop computing. It provides a range of features and
tools, including a graphical user interface, a powerful command-line
interface, and a variety of built-in applications. macOS offers seamless
integration with other Apple devices, such as iPhones and iPads,
through features like Handoff and Continuity. It also has robust
multimedia capabilities, with a focus on creativity and productivity.
macOS receives regular updates and new features, ensuring a modern
computing experience for Mac users. It is widely regarded for its
reliability, performance, and intuitive user experience.

3. WINDOWS –
Windows is a widely used operating system developed by Microsoft. It has

dominated the personal computer market for many years. Windows


provides a user-friendly interface with a graphical user interface (GUI) that
allows users to interact with their computers easily. It supports a wide
range of hardware and software applications, making it compatible with
various devices and software ecosystems. Windows offers a vast
collection of software and games, making it a popular choice for users
who require extensive software support. It provides features like
multitasking, file management, and a comprehensive control panel for
system customization. Windows also includes robust security measures,
such as antivirus software and built-in firewall protection. Regular
updates from Microsoft ensure the operating system's stability, security,
and compatibility. Overall, Windows offers a versatile and accessible
platform for personal and professional computing needs.

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

4. ANDROID –
Android is a mobile operating system developed by Google. It is based on
the Linux kernel and is primarily designed for touchscreen devices such
as smartphones and tablets. Android has become the most widely used
mobile operating system globally. It offers a rich ecosystem of apps
through the Google Play Store and supports a wide range of devices from
various manufacturers. Android provides a customizable user interface,
allowing users to personalize their devices with widgets, themes, and
launchers. It includes features like multitasking, notification system, and
integration with Google services such as Gmail, Maps, and Drive. Android
also supports advanced capabilities like voice recognition, NFC (Near
Field Communication), and mobile payments. With regular updates,
Android continues to evolve with new features and improvements, making

it a versatile and user-friendly operating system for mobile devices.

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

Practical No. 4
Objective – Calculate WT, TAT, Avg. WT & Avg. TAT
in FCFS Scheduling.
#include <stdio.h>
int main() {
int pid[10];
int bt[10];
int n;
prin ("Enter the number of processes: ");
scanf("%d",&n);
prin ("Enter process id of all the processes: ");
for(int i=0;i<n;i++)
{
scanf("%d",&pid[i]);
}
prin ("Enter burst me of all the processes: ");

for(int i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
int i,wt[n];
wt[0]=0;

//for calcula ng wai ng me for each process


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

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

wt[i]=bt[i-1]+wt[i-1];
}
prin ("ProcessID BurstTime Wai ngTime Turn
AroundTime\n");
float twt=0.0;
float tat=0.0;
for(i=0;i<n;i++)
{
prin ("%d\t\t\t",pid[i]);
prin ("%d\t\t\t",bt[i]);
prin ("%d\t\t\t",wt[i]);

//calcula ng and prin ng turnaround me of each

process prin ("%d\t\t\t\t",bt[i]+wt[i]); prin ("\n");

//for calcula ng total wai ng me


twt+=wt[i];

//for calcula ng total turnaround me


tat+=(wt[i]+bt[i]);
}
float a ,awt;

//for calcula ng average wai ng me

awt=twt/n;

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

//for calcula ng average turnaround me


a =tat/n;
prin ("Avg. wai ng me=%f\n",awt);

prin ("Avg. turnaround me=%f\n",a );


return 0;
}

Output:
Enter the number of processes: 4
Enter process id of all the processes: 1
2
3
4
Enter burst time of all the processes: 7
3
1
4
ProcessID BurstTime WaitingTime Turn AroundTime
1 7 0 7
2 3 7 10
3 1 10 11
4 4 11 15
Avg. waiting time=7.000000
Avg. turnaround time=10.750000

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

Practical No. 5
Objective – Calculate WT, TAT, Avg. WT & Avg.
TAT in SJF Scheduling.
#include <stdio.h>
int main()
{
//Matrix for storing Process Id, Burst Time, Average Waiting
Time and Average Turn Around Time.
int A[100][4];
int i,j,n,total=0,index,temp;
float avg_wt,avg_tat;
printf("Enter the number of process: ");
scanf("%d",&n);
printf("Enter Burst Time:\n");

//User Input Burst Time and allotting Process Id.


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

//Sorting process according to their Burst Time.


for(i=0;i<n;i++)
{
index=i;
for(j=i+1;j<n;j++)
if(A[j][1]<A[index][1])
index=j;
temp=A[i][1];
A[i][1]=A[index][1];
A[index][1]=temp;
temp=A[i][0];

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

A[i][0]=A[index][0];
A[index][0]=temp;
}
A[0][2]=0;

//Calculation of Waiting Times


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

//Calculations of Turn Around Time and Printing the data.


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 Turn Around Time=%f",avg_tat);

return 0;
}

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

OUTPUT:

Enter the number of process: 5


Enter Burst Time:
P1: 12
P2: 9
P3: 2
P4: 11
P5: 7
P BT WT TAT
P3 2 0 2
P5 7 2 9
P2 9 9 18
P4 11 18 29
P1 12 29 41

Average Waiting Time=11.600000


Average Turn Around Time=19.799999

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

Practical No. 6
Objective – Calculate WT, TAT, Avg. WT & Avg.
TAT in SRTF Scheduling.
#include <stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;

float avg_wt,avg_tat;

printf("\n Enter number of Processes: ");


scanf("%d",&n);
printf("Enter Burst Times: ");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
pos=i;
for(j=j+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;

}
temp=bt[i];

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=(float)total/n;
total=0;
printf("\nGANTT CHART: ");
printf("\n\tP[i]\tBT\tWT\tTAT");
printf("\n\t+_____________________________+");

for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\n\tP[%d]\t%d\t%d\t%d",p[i],bt[i],wt[i],tat[i]);

}
avg_tat=(float)total/n;
printf("\n\nAverage Waiting Time: %3f units",avg_wt);

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

printf("\n\Average Turn Around Time: %3f units\


n",avg_tat); return 0;
}

OUTPUT:
Enter number of Processes: 5
Enter Burst Times: 7 8 3 2 9
GANTT CHART:
P[i] BT WT TAT
+_____________________________+
P[4] 2 0 2
P[2] 8 2 10
P[3] 3 10 13
P[1] 7 13 20
P[5] 9 20 29

Average Waiting Time: 9.000000 units


Average Turn Around Time: 14.800000 units

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

Practical No. 7
Objective – Write a program on Priority CPU
Scheduling using C.
#include <stdio.h>
#include<conio.h>
void main()
{
int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i,j;

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

scanf("%d",&n);

printf("\n Enter process: time priorities \n");


for(i=0;i<n;i++)
{
printf("\n Process no %d: ",i+1);
scanf("%d %d",&pt[i],&pp[i]);
p[i]=i+1;
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(pp[i]<pp[j])
{
x=pp[i];
pp[i]=pp[j];
pp[j]=x;

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

x=pt[i];
pt[i]=pt[j];
pt[j]=x;
x=p[i];
pt[i]=pt[j];
pt[j]=x;
x=p[i];
p[i]=p[j];
p[j]=x;
}
}
}
w[0]=0;
awt=0;
t[0]=pt[0];
atat=t[0];
for(i=1;i<n;i++)
{
w[i]=t[i-1];
awt+=w[i];
t[i]=w[i]+pt[i];
atat+=t[i];
}
printf("\n\n Job \t Burst Time \t Wait Time \t Turn Around Time \t
Priority \n");
for(i=0;i<n;i++)
printf("\n %d \t\t %d \t\t %d \t\t %d \t\t %d \n",p[i],pt[i],w[i],t[i],pp[i]);

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

awt/=n;
atat/=n;
printf("\n Average Wait Time: %d\n",awt);
printf("\n Average Turn Around Time: %d\
n",atat); getch();
}

OUTPUT:
Enter the number of process: 4

Enter process: time priorities

Process no 1: 7 3

Process no 2: 3 1

Process no 3: 4 2

Process no 4: 2 4

Job Burst Time Wait Time Turn Around Time Priority

4 7 0 7 4

1 3 7 10 3

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

3 2 10 12 2

2 2 12 14 1

Average Wait Time: 7

Average Turn Around Time: 10

GARIMA CHAUDHARY B.TECH(CSE) 2100010100022


OS LAB MANUAL

Practical No. 3
Objective – To read student data from data
file on Secondary Storage.
#include <stdio.h>
#include<stdlib.h>
int main()
{
int data;
FILE *fptr;
if((fptr=fopen("C:\\test.txt","r"))==NULL)
{
printf("Error in opening file\n");
exit(1);
}
fscanf(fptr,"%d",&data);
printf("The value of n is %d",data);
fclose(fptr);
return 0;
}

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

OUTPUT:

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

Practical No. 2
Objective – Write a program in C to write student
data obtained to a data file on Secondary Storage.

#include <stdio.h>
#include<stdlib.h>

int main()
{
int data;
FILE *fptr;
fptr = fopen("C:\\test.txt","w");
if(fptr==NULL)
{
printf("Error in opening File\n");
exit(1);
}
printf("Enter some data: ");
scanf("%d",&data);
fprintf(fptr,"%d",data);
fclose(fptr);
return 0;
}

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

OUTPUT:

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

INDEX
SR.NO. PRACTICAL NAME TEACHER’S
SIGNATURE
1. Study of five most commonly used OS.

2. Write a program in C to write


student data obtained to a data file
on Secondary Storage.
3. To read student data from data
file on Secondary Storage.
4. Calculate WT, TAT, Avg. WT & Avg.
TAT in FCFS Scheduling.
5. Calculate WT, TAT, Avg. WT & Avg.
TAT in SJF Scheduling.
6. Calculate WT, TAT, Avg. WT & Avg.
TAT in SRTF Scheduling.
7. Calculate WT, TAT, Avg. WT & Avg.
TAT in Priority Scheduling.
8. Calculate WT, TAT, Avg. WT & Avg.
TAT in RR Scheduling.
9. To implement page replacement
algorithm using FIFO.

10. Implement Page Replacement


Algorithm using LRU.

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

Practical No. 8
Objective – Calculate WT, TAT, Avg. WT & Avg.
TAT in RR Scheduling.

#include<stdio.h>
int main()
{
int cnt,j,n,t,remain,flag=0,tq;
int wt=0,tat=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(cnt=0;cnt<n;cnt++)
{
printf("Enter Arrival Time and Burst Time for Process Process
Number %d :",cnt+1);
scanf("%d",&at[cnt]);
scanf("%d",&bt[cnt]);
rt[cnt]=bt[cnt];
}
printf("Enter Time Quantum:\t");
scanf("%d",&tq);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(t=0,cnt=0;remain!=0;)
{
if(rt[cnt]<=tq && rt[cnt]>0)

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

{
t+=rt[cnt];
rt[cnt]=0;
flag=1;
}
else if(rt[cnt]>0)
{
rt[cnt]-=tq;
t+=tq;
}
if(rt[cnt]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",cnt+1,t-at[cnt],t-at[cnt]-bt[cnt]);

wt+=t-at[cnt]-bt[cnt];
tat+=t-at[cnt];
flag=0;
}
if(cnt==n-1)
cnt=0;
else if(at[cnt+1]<=t)
cnt++;
else
cnt=0;
}
printf("\nAverage Waiting Time= %f\n",wt*1.0/n);

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

printf("Avg Turnaround Time =


%f",tat*1.0/n); return 0;
}

OUTPUT:

Enter Total Process: 4


Enter Arrival Time and Burst Time for Process Process Number

1 :0 5 Enter Arrival Time and Burst Time for Process Process

Number 2 :1 4 Enter Arrival Time and Burst Time for Process

Process Number 3 :2 2 Enter Arrival Time and Burst Time for

Process Process Number 4 :4 1 Enter Time Quantum: 2

Process |Turnaround Time|Waiting Time

P[3] | 4 | 2
P[4] | 3 | 2
P[2] | 10 | 6
P[1] | 12 | 7

Average Waiting Time= 4.250000


Avg Turnaround Time = 7.250000

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

Practical No. 9
Objective – To implement page replacement
algorithm using FIFO.

#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF
PAGES: "); scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER : ");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES : ");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tref string\t page frames\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

}
printf("Page Fault Is: %d",count);
return 0;
}

OUTPUT:

ENTER THE NUMBER OF PAGES: 18

ENTER THE PAGE NUMBER : 0 4 1 4 2 4 3 4 2 4 0 4 1 4 2 4 3 4

ENTER THE NUMBER OF FRAMES : 3


ref string page frames
0 0 -1 -1
4 0 4 -1
1 0 4 1
4
2 2 4 1
4
3 2 3 1
4 2 3 4
2
4
0 0 3 4
4
1 0 1 4
4
2 0 1 2

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

4 4 1 2
3 4 3 2
4
Page Fault Is: 11

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

Practical No. 10
Objective – Implement Page Replacement
Algorithm using LRU.
#include<stdio.h>
int main()
{
int

q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];

printf("Enter no of pages:"); scanf("%d",&n);

printf("Enter the reference string:");


for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of frames:");
scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{
c1=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
}

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

if(c1==f)
{
c++;
if(k<f)
{
q[k]=p[i];
k++;
for(j=0;j<k;j++)
printf("\t%d",q[j]);

printf("\n");
}
else
{
for(r=0;r<f;r++)
{
c2[r]=0;
for(j=i-1;j<n;j--)

{
if(q[r]!=p[j])
c2[r]++;
else
break;
}
}
for(r=0;r<f;r++)
b[r]=c2[r];

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

for(r=0;r<f;r++)
{
for(j=r;j<f;j++)
{
if(b[r]<b[j])
{
t=b[r];
b[r]=b[j];
b[j]=t;
}
}
}
for(r=0;r<f;r++)
{
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
}
printf("\n");
}
}
}
printf("\nThe no of page faults is %d",c);

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022


OS LAB MANUAL

OUTPUT:

Enter no of pages:10
Enter the reference string:7 5 9 4 3 7
9 6 2 1 Enter no of frames:3

7
7 5
7 5 9
4 5 9
4 3 9
4 3 7
9 3 7
9 6 7
9 6 2
1 6 2

The no of page faults is 10

GARIMA CHAUDHARY B.TECH (CSE) 2100010100022

You might also like