Os Lab Manual
Os Lab Manual
Os Lab Manual
Borawan(M.P.)
Lab Manual
Subject:-Operating System
Index
S No. Date Name Sign of Remark
Teacher
1 Introduction of operating system and its typs
3 IO System Calls
6 Priority Scheduling
Experiment No. 1
Operating System
Introduction
An Operating system is software that creates a relation between the User, Software and
Hardware. It is an interface between the all. All the computers need basic software known as an
Operating System (OS) to function.
The OS acts as an interface between the User, Application Programs, Hardware and the
System Peripherals. The OS is the first software to be loaded when a computers starts up. The
entire application programs are loaded after the OS.
1. Single User: If the single user Operating System is loaded in computer’s memory; the
computer would be able to handle one user at a time.
1. Multi user: If the multi-user Operating System is loaded in computer’s memory; the
Operating System provi des a text based interface called command p rompt. From the
command prompt commands c an be issued to perform file and disk manag ement and to run
program. Results of these comm ands are presented to the user as text message.
C:\>-
The command prompt can be an alphabet followed by one colon (:), one back slash (\), one greater
than sign (>) and one bli nking element called cursor (_).
Process Scheduling
Processes are the Small Programs those are executed by the user according to
their Request. CPU Executes all the Process according to Some Rules or Some
Schedule. Scheduling ist hat in which each process have Some Amount of Time of
CPU. Scheduling Provides Time of CPU to the Each Process.
A process once allocated the CPU keeps it until releasing the CPU either by terminating
or requesting I/O. For example, interrupted process is allowed to continujre running after
interrupt handling is done with.
Experiment No. 2
PROCESS SYSTEM CALLS
AIM:
ALGORITHM:
2. Declare the pid and get the pid by using the getpid() method.
4. Check if(pid==0) then print the child process id and then print the parent process
value. Otherwise print
#include<stdlib.h>
#include<unistd.h>
if(pid<0)
printf("fork failed");
exit(1);
else if(pid==0)
execlp("whoami","ls",NULL);
exit(0);
else
wait(NULL);
exit(0);
OUTPUT:
RESULT:
Thus the process system call program was executed and verified successfully
Experiment No. 3
IO SYSTEM CALLS
AIM:
ALGORITHM:
2. open a file for O_RDWR for R/W,O_CREATE for creating a file , O_TRUNC
for truncate a file
3. Using getchar(), read the character and stored in the string[] array
5. Then the first is opened for read only mode and read the characters and displayed It
and close the file
#include<unistd.h>
#include<string.h>
#include<fcntl.h>
main( )
int fd[2];
char buf2[50];
fd[0]=open("file1",O_RDWR);
fd[1]=open("file2",O_RDWR);
scanf("\n %s",buf1);
close(fd[0]);
close(fd[1]);
printf("\n");
return 0;
OUTPUT:
RESULT:
Thus the I/O system call program was executed and verified successfully.
Experiment No. 4
JIT (Computer Science & Engineer) Page 12
Operating System Lab
AIM:
To write the program to implement CPU & scheduling algorithm for first come first
serve scheduling.
ALGORITHM:
4. Process for(i=2;i<=n;i++),wt.p[i]=p[i-1]+bt.p[i-1].
5. The waiting time of all the processes is summed then average value time is calculated.
6. The waiting time of each process and average times are displayed
struct process
int pid;
int bt;
int wt,tt;
}p[10];
int main()
p[i].pid=i;
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
p[i].wt=p[i-1].bt+p[i-1].wt; p[i].tt=p[i].bt+p[i].wt;
i ++;
i=1;
totwt=tottt=0;
tottt=p[i].tt+tottt;
i++;}
return 0;
OUTPUT:
Process sid bt wt tt
1 2 0 2
2 4 2 6
3 6 6 12
avg1=2 avg2=6
RESULT:
Thus the FIFO process scheduling program was executed and verified successfully
Experiment No. 5
AIM:
To write a program to implement cpu scheduling algorithm for shortest job
first scheduling.
ALGORITHM:
1. Start the program. Get the number of processes and their burst time.
5. The waiting time of all the processes summed and then the average time is calculate
6. The waiting time of each processes and average time are displayed.
#include<stdio.h>
#include<conio.h>
struct process
int pid;
int bt;
int wt;
int tt;
}p[10],temp;
int main()
int i,j,n,totwt,tottt;
float avg1,avg2;
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++)
p[i].pid=i;
scanf("%d",&p[i].bt);
for(i=1;i<n;i++){
for(j=i+1;j<=n;j++)
if(p[i].bt>p[j].bt)
temp.pid=p[i].pid;
p[i].pid=p[j].pid;
p[j].pid=temp.pid;
temp.bt=p[i].bt;p[i].bt=p[j].bt;
p[j].bt=temp.bt;
}}}
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n){
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt;
i++;
i=1;
totwt=tottt=0;
while(i<=n){
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;
} avg1=totwt/n;
avg2=tottt/n;
printf("\nAVG1=%f\t AVG2=
%f",avg1,avg2); getch();
return 0; }
OUTPUT:
processid bt wt tt
1 2 0 2
2 4 2 6
3 6 6 12
AVG1=2.000000 AVG2=6.000000
RESULT:
Thus the SJF program was executed and verified successfully
Experiment No. 6
PRIORITY SCHEDULING
AIM:
ALGORITHM:
#include<conio.h>
struct process
int pid;
int bt;
int wt;
int tt;
int prior;
p[10],temp;
int main()
int i,j,n,totwt,tottt,arg1,arg2;
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++)
p[i].pid=i;
scanf("%d",&p[i].bt);
scanf("%d",&p[i].prior);
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
{
if(p[i].prior>p[j].prior)
temp.pid=p[i].pid;
p[i].pid=p[j].pid;
p[j].pid=temp.pid;
temp.bt=p[i].bt;
p[i].bt=p[j].bt;
p[j].bt=temp.bt;
temp.prior=p[i].prior;
p[i].prior=p[j].prior;
p[j].prior=temp.prior;
p[i].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt;
i++;
i=1;
totwt=tottt=0;
while(i<=n)
{
printf("\n%d\t %d\t %d\t %d\t",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;
arg1=totwt/n;
arg2=tottt/n;
getch();
return 0;
OUTPUT:
process to bt wt tt
1 4 0 4 4
2 6 4 10 14
3 2 10 12 22
avg1=4 avg2=8
RESULT:
Thus the priority scheduling program was executed and verified successfully
Experiment No. 7
ROUND ROBIN SCHEDULING
AIM:
ALGORITHM:
3. The burst time of each process is divided and the quotients are stored on the
round Robin array.
4. According to the array value the waiting time for each process and the
average time are calculated as line the other scheduling.
5. The waiting time for each process and average times are displayed.
#include<conio.h>
struct process
int pid,bt,tt,wt;
};
int main()
int i,j,k,tot=0,m,n;
float wttime=0.0,tottime=0.0,a1,a2;
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++){
x[i].pid=i;
scanf("%d",&x[i].bt);
tot=tot+x[i].bt;
p[0].tt=0;
k=1;
scanf("%d",&m);
for(j=1;j<=tot;j++)
for(i=1;i<=n;i++)
{
if(x[i].bt !=0)
p[k].pid=i;
if(x[i].bt-m<0)
p[k].wt=p[k-1].tt;
p[k].bt=x[i].bt;
p[k].tt=p[k].wt+x[i].bt;
x[i].bt=0;
k++;
else
p[k].wt=p[k-1].tt;
p[k].tt=p[k].wt+m;
x[i].bt=x[i].bt-m;
k++;
for(i=1;i<k;i++){
wttime=wttime+p[i].wt;
tottime=tottime+p[i].tt;
a1=wttime/n;
a2=tottime/n;
}
getch();
return 0;
OUTPUT:
process id wt tt
1 0 2
2 2 4
3 4 6
1 6 7
process id wt tt
2 7 9
3 9 11
2 11 12
3 12 14
3 14 15
RESULT:
Thus the Round Robin scheduling program was executed and verified successfully.
Experiment No. 8
JIT (Computer Science & Engineer) Page 26
Operating System Lab
AIM:
ALGORITHM:
1. Declare variable for producer & consumer as pthread-t-tid produce tid consume.
void main()
in = 0;
out = 0;
bufsize = 10;
while(choice !=3)
scanf("%d", &choice);
switch(choice)
case 1: if((in+1)%bufsize==out)
printf("\nBuffer is Full");
else
scanf("%d", &produce);
buffer[in] = produce;
in = (in+1)%bufsize;
break;
printf("\nBuffer is Empty");
else
{
consume = buffer[out];
out = (out+1)%bufsize;
break;
} } }
OUTPUT:
Buffer is Empty
RESULT:
Thus the producer consumer program was executed and verified successfully.
Experiment No. 9
ALGORITHM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
clrscr();
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
for(i=1;i<=nf;i++)
printf("File %d:",i);
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
ff[i]=j;
highest=temp;
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",
i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
OUTPUT:
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 3 7 6
2 4 1 5 1
RESULT:
Thus the First Bit and Best Fit program was executed and verified successfully.
Experiment No. 10
SIMULATE PAGE REPLACEMENT ALGORITHMS FIFO
AIM:
ALGORITHM:
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
void main()
clrscr();
scanf("%d",&nof);
scanf("%d",&nor);
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
frm[i]=-1;
printf("\n");
for(i=0;i<nor;i++)
flag=0;
for(j=0;j<nof;j++)
if(frm[j]==ref[i])
{
flag=1;
break;
}}
if(flag==0)
pf++;
victim++;
victim=victim%nof;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
} }
getch();
OUTPUT:
564123
...................................... 5 6 4 1 2 3
Reference np5-> 5 -1 -1 -1
Reference np6-> 5 6 -1 -1
Reference np4-> 5 6 4 -1
Reference np1-> 5 64 1
Reference np2-> 2 64 1
Reference np3-> 2 34 1
RESULT:
Thus the program FIFO page replacement was successfully executed.