Os File
Os File
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
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
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
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;
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]);
awt=twt/n;
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
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");
A[i][0]=A[index][0];
A[index][0]=temp;
}
A[0][2]=0;
return 0;
}
OUTPUT:
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;
}
temp=bt[i];
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);
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
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;
scanf("%d",&n);
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]);
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
Process no 1: 7 3
Process no 2: 3 1
Process no 3: 4 2
Process no 4: 2 4
4 7 0 7 4
1 3 7 10 3
3 2 10 12 2
2 2 12 14 1
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;
}
OUTPUT:
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;
}
OUTPUT:
INDEX
SR.NO. PRACTICAL NAME TEACHER’S
SIGNATURE
1. Study of five most commonly used OS.
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)
{
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);
OUTPUT:
P[3] | 4 | 2
P[4] | 3 | 2
P[2] | 10 | 6
P[1] | 12 | 7
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");
}
printf("Page Fault Is: %d",count);
return 0;
}
OUTPUT:
4 4 1 2
3 4 3 2
4
Page Fault Is: 11
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];
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];
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);
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