SlideShare a Scribd company logo
TELEGRAM : CLICK HERE WHATSAPP : CLICK HERE
Academic Year: 2023-24
LABORATORY MANUAL
SEMESTER : III
SUBJECT : Operating Systems
SUBCODE : BCS 303
NAME: ____________________________________________________________
USN: _____________________________________________________________
SECTION: __________________________________________________________
BATCH: ___________________________________________________________
PROGRAM OUTCOMES
Engineering Graduates will able to:
Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
Problem analysis: Identify, formulate, review research literature, and analyse complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis
of the information to provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modelling to complex engineering activities
with an understanding of the limitations.
The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice.
Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice. Individual and team work: Function effectively as an
individual, and as a member or leader in diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and
receive clear instructions.
Project management and finance: Demonstrate knowledge and understanding of the
Engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
Life -long learning: Recognize the need for and have the preparation and ability to engage in
independent and life -long learning in the broadest context of technological change.
INSTITUTE VISION AND MISSION
VISION
The East Point College of Engineering and Technology aspires to be a globally
acclaimed institution, recognized for excellence in engineering education, applied
research and nurturing students for holistic development.
MISSION
M1: To create engineering graduates through quality education and to nurture
innovation, creativity and excellence in teaching, learning and research
M2: To serve the technical, scientific, economic and societal developmental needs
of our communities
M3: To induce integrity, teamwork, critical thinking, personality development and
ethics in students and to lay the foundation for lifelong learning
DEPARTMENT VISION AND MISSION
VISION
The department orients towards identifying and exploring emerging global trends in
the fields of Artificial Intelligence and Data Science through academic excellence
and quality research, producing proficient professionals for a flourishing society.
MISSION
M1: To nurture students with quality education, life-long learning, values and ethics.
M2: To produce ethical and competent professionals through comprehensive and
holistic methodologies that align with the global industry demands in Artificial
Intelligence and Data Science.
PROGRAM EDUCATIONAL OBJECTIVES (PEOs)
1. Graduates will possess the ability to apply their knowledge of fundamental
engineering, Computer Science and Data Science.
2. Graduates will have sound intercommunication skills, ethical values and
responsibilities to work and serve for the development of the society.
3. Graduates will be able to understand, interpret, model and implement the
Artificial Intelligence and Data Science based solutions for real world
problems.
PROGRAM SPECIFIC OUTCOMES (PSOs)
1. To cater and enhance the analytical and technical skills of the graduates in
order to be ready for the professional development, research and pursue
higher education.
2. To formulate solutions for the real-world problems with the application of
Data Science.
Department of Computer science and Engg.
basic engineering principles and technical skills of Artificial Intelligence and
COURSE LEARNING OBJECTIVES
• To Demonstrate the need for OS and different types of OS
• To discuss suitable techniques for management of different resources
• To demonstrate different APIs/Commands related to processor, memory,
storage and file system management.
COURSE OUTCOMES
CO1: Explain the structure and functionality of operating system
CO2: Apply appropriate CPU scheduling algorithms for the given problem.
CO3: Analyze the various techniques for process synchronization and deadlock handling.
CO4: Apply the various techniques for memory management
CO5: Explain file and secondary storage management strategies.
CO6: Describe the need for information protection mechanisms
Sl.N
O
Experiments
1 Develop a c program to implement the Process system calls (fork (), exec(), wait(), create process,
terminate process)
2 Simulate the following CPU scheduling algorithms to find turnaround time and waiting time a) FCFS
b) SJF c) Round Robin d) Priority.
3 Develop a C program to simulate producer-consumer problem using semaphores.
4 Develop a C program which demonstrates interprocess communication between a reader
process and a writer process. Use mkfifo, open, read, write and close APIs in your program.
5
Develop a C program to simulate Bankers Algorithm for DeadLock Avoidance.
6 Develop a C program to simulate the following contiguous memory allocation Techniques:
a) Worst fit b) Best fit c) First fit.
7 Develop a C program to simulate page replacement algorithms:
a) FIFO b) LRU
8 Simulate following File Organization Techniques
a) Single level directory b) Two level directory
9 Develop a C program to simulate the Linked file allocation strategies.
10 Develop a C program to simulate SCAN disk scheduling algorithm.
Course outcomes (Course Skill Set):
At the end of the course, the student will be able to:
CO 1. Explain the structure and functionality of operating system
CO 2. Apply appropriate CPU scheduling algorithms for the given problem.
CO 3. Analyse the various techniques for process synchronization and deadlock handling.
CO 4. Apply the various techniques for memory management
CO 5. Explain file and secondary storage management strategies.
CO 6. Describe the need for information protection mechanisms
Assessment Details (both CIE and SEE)
The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End Exam (SEE) is 50%. The
minimum passing mark for the CIE is 40% of the maximum marks (20 marks out of 50) and for the SEE minimum
passing mark is 35% of the maximum marks (18 out of 50 marks). A student shall be deemed tohave satisfied
the academic requirements and earned the credits allotted to each subject/ course if the student secures a
minimum of 40% (40 marks out of 100) in the sum total of the CIE (Continuous Internal Evaluation) and SEE
(Semester End Examination) taken together.
CIE for the theory component of the IPCC (maximum marks 50)
● IPCC means practical portion integrated with the theory of the course.
● CIE marks for the theory component are 25 marks and that for the practical component is 25 marks.
● 25 marks for the theory component are split into 15 marks for two Internal Assessment Tests (Two Tests,
each of 15 Marks with 01-hour duration, are to be conducted) and 10 marks for other assessment methods
mentioned in 22OB4.2. The first test at the end of 40-50% coverage of the syllabus and the second
testafter covering 85-90% of the syllabus.
● Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for the
theorycomponent of IPCC (that is for 25 marks).
● The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of IPCC.
CIE for the practical component of the IPCC
● 15 marks for the conduction of the experiment and preparation of laboratory record, and 10 marks
for the test to be conducted after the completion of all the laboratory sessions.
● On completion of every experiment/program in the laboratory, the students shall be evaluated
including viva-voce and marks shall be awarded on the same day.
● The CIE marks awarded in the case of the Practical component shall be based on the continuous
evaluationof the laboratory report. Each experiment report can be evaluated for 10 marks. Marks of
all experiments’ write-ups are added and scaled down to 15 marks.
● The laboratory test (duration 02/03 hours) after completion of all the experiments shall be conducted
for 50 marks and scaled down to 10 marks.
● Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory
component of IPCC for 25 marks.
● The student has to secure 40% of 25 marks to qualify in the CIE of the practical component of the IPCC.
SEE for IPCC
Suggested Learning Resources:
Textbooks
1. Abraham Silberschatz, Peter Baer Galvin, Greg Gagne, Operating System Principles 8th
edition,Wiley-India, 2015
Reference Books
1. Ann McHoes Ida M Fylnn, Understanding Operating System, Cengage Learning, 6th Edition
2. D.M Dhamdhere, Operating Systems: A Concept Based Approach 3rd Ed, McGraw- Hill,
2013.
3. P.C.P. Bhatt, An Introduction to Operating Systems: Concepts and Practice 4th Edition,
PHI(EEE),2014.
4. William Stallings Operating Systems: Internals and Design Principles, 6th Edition, Pearson.
Table of Content
Sl. No. Content
1
Develop a c program to implement the Process system calls (fork (), exec(),
wait(), create process,terminate process)
2
Simulate the following CPU scheduling algorithms to find turnaround time
and waiting time a) FCFS
b) SJF c) Round Robin d) Priority.
3
Develop a C program to simulate producer-consumer problem using
semaphores.
4
Develop a C program which demonstrates interprocess communication
between a reader process and a writer process. Use mkfifo, open, read,
write and close APIs in your program.
5
Develop a C program to simulate Bankers Algorithm for DeadLock
Avoidance.
6
Develop a C program to simulate the following contiguous memory allocation
Techniques:
a) Worst fit b) Best fit c) First fit.
7
Develop a C program to simulate page replacement algorithms:
a) FIFO b) LRU
8
Simulate following File Organization Techniques
a) Single level directory b) Two level directory
9 Develop a C program to simulate the Linked file allocation strategies.
10 Develop a C program to simulate SCAN disk scheduling algorithm.
Program-1
Develop a c program to implement the Process system calls (fork (), exec (), wait (),
create process,terminate process)
#include<stdio.h> // printf()
#include<stdlib.h> // exit()
#include<sys/types.h> // pid_t
#include<sys/wait.h> // wait()
#include<unistd.h> // fork
int main(int argc, char **argv)
{
pid_t pid;
pid = fork();
if(pid==0)
{
printf("It is the child process and pid is %dn",getpid());
int i=0;
for(i=0;i<8;i++)
{
printf("%dn",i);
}
exit(0);
}
else if(pid > 0)
{
printf("It is the parent process and pid is %dn",getpid());
int status;
wait(&status);
printf("Child is reapedn");
}
else
{
printf("Error in forking..n");
exit(EXIT_FAILURE);
}
return 0;
}
Output:
Program-2
Simulate the following CPU scheduling algorithms to find turnaround time and
waiting time
a) FCFS
#include<stdio.h>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20): ");
scanf("%d",&n);
printf("nEnter Process Burst Time:n");
for(i=0;i<n;i++)
{
printf("P[%d]: ",i+1);
scanf("%d",&bt[i]);
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
printf("nProcessttBurst TimetWaiting TimetTurnaround Time");
//calculating turnaround time
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("nP[%d]tt%dtt%dtt%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i;
avtat/=i;
printf("nnAverage Waiting Time:%d",avwt);
printf("nAverage Turnaround Time:%d",avtat);
return 0;
}
Output:
b) SJF
#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("Enter number of process: ");
scanf("%d",&n);
printf("nEnter Burst Time:n");
for(i=0;i<n;i++)
{
printf("p%d: ",i+1);
scanf("%d",&bt[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{ pos=i;
for(j=i+1;j<n;j++)
{ if(bt[j]<bt[pos])
pos=j;
}
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;
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("nProcesst Burst Time tWaiting TimetTurnaround Time");
for(i=0;i<n;i++)
{ tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("np%dtt %dtt %dttt%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=(float)total/n;
printf("nnAverage Waiting Time=%f",avg_wt);
printf("nAverage Turnaround Time=%fn",avg_tat);
return 0;
}
Output:
c) Round Robin
#include<stdio.h>
int main()
{
int count,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:t");
scanf("%d",&time_quantum);
printf("nnProcesst|Turnaround Time|Waiting Timenn");
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum && rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("P[%d]t|t%dt|t%dn",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
printf("nAverage Waiting Time= %fn",wait_time*1.0/n);
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n);
return 0;
}
Output:
d) Priority
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);
printf("nEnter Burst Time and Priorityn");
for(i=0;i<n;i++)
{
printf("nP[%d]n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=total/n;
total=0;
printf("nProcesst Burst Time tWaiting TimetTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("nP[%d]tt %dtt %dttt%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=total/n;
printf("nnAverage Waiting Time=%d",avg_wt);
printf("nAverage Turnaround Time=%dn",avg_tat);
return 0;
}
Output:
Program-3
Develop a C program to simulate producer-consumer problem using
semaphores.
#include<stdio.h>
void main()
{
int buffer[10], bufsize, in, out, produce, consume, choice=0;
in = 0;
out = 0;
bufsize = 10;
while(choice !=3)
{
printf("n 1. Produce t 2. Consume t3. Exit");
printf("n Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1: if((in+1)%bufsize==out)
printf("n Buffer is Full");
else
{
printf("nEnter the value: ");
scanf("%d", &produce);
buffer[in] = produce;
in = (in+1)%bufsize;
}
break;
case 2: if(in == out)
printf("nBuffer is Empty");
else
{
consume = buffer[out];
printf("nThe consumed value is %d", consume);
out = (out+1)%bufsize;
}
break;
} } }
Output:
Program-4
Develop a C program which demonstrates inter-process communication
between a reader process and a writer process. Use mkfifo, open, read, write
and close APIs in your program.
/*Writer Process*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
int fd;
char buf[1024];
/* create the FIFO (named pipe) */
char * myfifo = "/tmp/myfifo";
mkfifo(myfifo, 0666);
printf("Run Reader process to read the FIFO Filen");
fd = open(myfifo, O_WRONLY);
write(fd,"Hi", sizeof("Hi"));
/* write "Hi" to the FIFO */
close(fd);
unlink(myfifo); /* remove the FIFO */
return 0;
}
/* Reader Process*/
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#define MAX_BUF 1024
int main()
{
int fd;
/* A temp FIFO file is not created in reader */
char *myfifo = "/tmp/myfifo";
char buf[MAX_BUF];
/* open, read, and display the message from the FIFO */
fd = open(myfifo, O_RDONLY);
read(fd, buf, MAX_BUF);
printf("Writer: %sn", buf);
close(fd);
return 0;
}
Instructions for Execution:
1. Run Reader Process
2. Then Run Writer Process
Program-5
Develop a C program to simulate Bankers Algorithm for DeadLock Avoidance.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int Max[10][10], need[10][10], alloc[10][10], avail[10], completed[10], safeSequence[10];
int p, r, i, j, process, count;
count = 0;
printf("Enter the no of processes : ");
scanf("%d", &p);
for(i = 0; i< p; i++)
completed[i] = 0;
printf("nnEnter the no of resources : ");
scanf("%d", &r);
printf("nnEnter the Max Matrix for each process : ");
for(i = 0; i < p; i++)
{
printf("nFor process %d : ", i + 1);
for(j = 0; j < r; j++)
scanf("%d", &Max[i][j]);
}
printf("nnEnter the allocation for each process : ");
for(i = 0; i < p; i++)
{
printf("nFor process %d : ",i + 1);
for(j = 0; j < r; j++)
scanf("%d", &alloc[i][j]);
}
printf("nnEnter the Available Resources : ");
for(i = 0; i < r; i++)
scanf("%d", &avail[i]);
for(i = 0; i < p; i++)
for(j = 0; j < r; j++)
need[i][j] = Max[i][j] - alloc[i][j];
do
{
printf("n Max matrix:tAllocation matrix:n");
for(i = 0; i < p; i++)
{
for( j = 0; j < r; j++)
printf("%d ", Max[i][j]);
printf("tt");
for( j = 0; j < r; j++)
printf("%d ", alloc[i][j]);
printf("n");
}
process = -1;
for(i = 0; i < p; i++)
{
if(completed[i] == 0)//if not completed
{
process = i ;
for(j = 0; j < r; j++)
{
if(avail[j] < need[i][j])
{
process = -1;
break;
}
}
}
if(process != -1)
break;
}
if(process != -1)
{
printf("nProcess %d runs to completion!", process + 1);
safeSequence[count] = process + 1;
count++;
for(j = 0; j < r; j++)
{
avail[j] += alloc[process][j];
alloc[process][j] = 0;
Max[process][j] = 0;
completed[process] = 1;
}
}
}
while(count != p && process != -1);
if(count == p)
{
printf("nThe system is in a safe state!!n");
printf("Safe Sequence : < ");
for( i = 0; i < p; i++)
printf("%d ", safeSequence[i]);
printf(">n");
}
else
printf("nThe system is in an unsafe state!!");
}
Output:
Program-6
Develop a C program to simulate the following contiguous memory allocation
Techniques
a) Worst fit
#include<stdio.h>
int main()
{
int fragments[10], blocks[10], files[10];
int m, n, number_of_blocks, number_of_files, temp, top = 0;
static int block_arr[10], file_arr[10];
printf("nEnter the Total Number of Blocks:t");
scanf("%d",&number_of_blocks);
printf("Enter the Total Number of Files:t");
scanf("%d",&number_of_files);
printf("nEnter the Size of the Blocks:n");
for(m = 0; m < number_of_blocks; m++)
{
printf("Block No.[%d]:t", m + 1);
scanf("%d", &blocks[m]);
}
printf("Enter the Size of the Files:n");
for(m = 0; m < number_of_files; m++)
{
printf("File No.[%d]:t", m + 1);
scanf("%d", &files[m]);
}
for(m = 0; m < number_of_files; m++)
{
for(n = 0; n < number_of_blocks; n++)
{
if(block_arr[n] != 1)
{
temp = blocks[n] - files[m];
if(temp >= 0)
{
if(top < temp)
{
file_arr[m] = n;
top = temp;
}
}
}
fragments[m] = top;
block_arr[file_arr[m]] = 1;
top = 0;
}
}
printf("nFile NumbertFile SizetBlock NumbertBlock SizetFragment");
for(m = 0; m < number_of_files; m++)
{
printf("n%dtt%dtt%dtt%dtt%d", m, files[m], file_arr[m], blocks[file_arr[m]], fragments[m]);
}
printf("n");
return 0;
}
Output:
b) Best Fit
#include<stdio.h>
void main()
{
int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
static int barray[20],parray[20];
printf("ntttMemory Management Scheme - Best Fit");
printf("nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of processes:");
scanf("%d",&np);
printf("nEnter the size of the blocks:-n");
for(i=1;i<=nb;i++)
{
printf("Block no.%d:",i);
scanf("%d",&b[i]);
}
printf("nEnter the size of the processes :-n");
for(i=1;i<=np;i++)
{
printf("Process no.%d:",i);
scanf("%d",&p[i]);
}
for(i=1;i<=np;i++)
{
for(j=1;j<=nb;j++)
{
if(barray[j]!=1)
{
temp=b[j]-p[i];
if(temp>=0)
if(lowest>temp)
{
parray[i]=j;
lowest=temp;
}
}
}
fragment[i]=lowest;
barray[parray[i]]=1;
lowest=10000;
}
printf("nProcess_notProcess_sizetBlock_notBlock_sizetFragment");
for(i=1;i<=np && parray[i]!=0;i++)
printf("n%dtt%dtt%dtt%dtt%d",i,p[i],parray[i],b[parray[i]],fragment[i]);
}
c) First Fit
#include<stdio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
printf("ntMemory Management Scheme - First Fit");
printf("nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("nEnter the size of the blocks:-n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-n");
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++)
{
if(bf[j]!=1) //if bf[j] is not allocated
{
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%dtt%dtt%dtt%dtt%d",
i,f[i],ff[i],b[ff[i]],frag[i]);
}
Output:
Program-7
Develop a C program to simulate page replacement algorithms
a) 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:n");
scanf("%d",&n);
printf("n ENTER THE PAGE NUMBER :n");
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 stringt page framesn");
for(i=1;i<=n;i++)
{
printf("%dtt",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("%dt",frame[k]);
}
printf("n");
}
printf("Page Fault Is %d",count);
return 0;
}
Output:
b) LRU
#include<stdio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],lrucal[50],count=0;
int lruvictim();
void main()
{
printf("nttt LRU PAGE REPLACEMENT ALGORITHM");
printf("n Enter no.of Frames....");
scanf("%d",&nof);
printf(" Enter no.of reference string..");
scanf("%d",&nor);
printf("n Enter reference string..");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
printf("nntt LRU PAGE REPLACEMENT ALGORITHM ");
printf("nt The given reference string:");
printf("n………………………………..");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
{
frm[i]=-1;
lrucal[i]=0;
} for(i=0;i<10;i++)
recent[i]=0;
printf("n");
for(i=0;i<nor;i++)
{
flag=0;
printf("nt Reference NO %d->t",ref[i]);
for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
if(count<=nof)
victim++;
else
victim=lruvictim();
pf++;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}
recent[ref[i]]=i;
}
printf("nnt No.of page faults...%d",pf);
}
int lruvictim()
{
int i,j,temp1,temp2;
for(i=0;i<nof;i++)
{
temp1=frm[i];
lrucal[i]=recent[temp1];
}
temp2=lrucal[0];
for(j=1;j<nof;j++)
{
if(temp2>lrucal[j])
temp2=lrucal[j];
}
for(i=0;i<nof;i++)
if(ref[temp2]==frm[i])
return i;
return 0;
}
Output:
Program-8
Simulate following File Organization Techniques
a) Single level directory
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main()
{
int i,ch;
char f[30];
dir.fcnt = 0;
printf("nEnter name of directory -- ");
scanf("%s", dir.dname);
while(1)
{
printf("nn1. Create Filet2. Delete Filet3. Search File n 4. Display Filest5. ExitnEnter your choice
-- ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("nEnter the name of the file -- ");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
case 2: printf("nEnter the name of the file -- ");
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f, dir.fname[i])==0)
{
printf("File %s is deleted ",f);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]); break; } }
if(i==dir.fcnt) printf("File %s not found",f);
else
dir.fcnt--;
break;
case 3: printf("nEnter the name of the file -- ");
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f, dir.fname[i])==0)
{
printf("File %s is found ", f);
break;
}
}
if(i==dir.fcnt)
printf("File %s not found",f);
break;
case 4: if(dir.fcnt==0)
printf("nDirectory Empty");
else
{
printf("nThe Files are -- ");
for(i=0;i<dir.fcnt;i++)
printf("t%s",dir.fname[i]);
}
break;
default: exit(0);
}
}
}
Output:
b) Two-Level Directory
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir[10];
void main()
{
int i,ch,dcnt,k;
char f[30], d[30];
dcnt=0;
while(1)
{
printf("nn1. Create Directoryt2. Create Filet3. Delete File");
printf("n4. Search Filett5. Displayt6. ExittEnter your choice -- ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("nEnter name of directory -- ");
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
case 2: printf("nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter name of the file -- ");
scanf("%s",dir[i].fname[dir[i].fcnt]);
printf("File created");
break;
}
if(i==dcnt)
printf("Directory %s not found",d);
break;
case 3: printf("nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter name of the file -- ");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{
if(strcmp(f, dir[i].fname[k])==0)
{
printf("File %s is deleted ",f);
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
}
}
printf("File %s not found",f);
goto jmp;
}
}
printf("Directory %s not found",d);
jmp : break;
case 4: printf("nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter the name of the file -- ");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{
if(strcmp(f, dir[i].fname[k])==0)
{
printf("File %s is found ",f);
goto jmp1;
}
}
printf("File %s not found",f);
goto jmp1;
}
}
printf("Directory %s not found",d);
jmp1: break;
case 5: if(dcnt==0)
printf("nNo Directory's ");
else
{
printf("nDirectorytFiles");
for(i=0;i<dcnt;i++)
{
printf("n%stt",dir[i].dname);
for(k=0;k<dir[i].fcnt;k++)
printf("t%s",dir[i].fname[k]);
}
}
break;
default:exit(0);
}
}
}
Output:
Program-9
Develop a C program to simulate the Linked file allocation strategies.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int f[50], p,i, st, len, j, c, k, a;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("Enter how many blocks already allocated: ");
scanf("%d",&p);
printf("Enter blocks already allocated: ");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
x: printf("Enter index starting block and length: ");
scanf("%d%d", &st,&len);
k=len;
if(f[st]==0)
{
for(j=st;j<(st+k);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("%d-------->%dn",j,f[j]);
}
else
{
printf("%d Block is already allocated n",j);
k++;
}
}
}
else
printf("%d starting block is already allocated n",st);
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit(0);
getch();
}
Output:
Program-10
Develop a C program to simulate SCAN disk scheduling algorithm.
#include <stdio.h>
int request[50];
int SIZE;
int pre;
int head;
int uptrack;
int downtrack;
struct max{
int up;
int down;
} kate[50];
int dist(int a, int b){
if (a > b)
return a - b;
return b - a;
}
void sort(int n){
int i, j;
for (i = 0; i < n - 1; i++){
for (j = 0; j < n - i - 1; j++){
if (request[j] > request[j + 1]){
int temp = request[j];
request[j] = request[j + 1];
request[j + 1] = temp;
}
}
}
j = 0;
i = 0;
while (request[i] != head){
kate[j].down = request[i];
j++;
i++;
}
downtrack = j;
i++;
j = 0;
while (i < n){
kate[j].up = request[i];
j++;
i++;
}
uptrack = j;
}
void scan(int n){
int i;
int seekcount = 0;
printf("SEEK SEQUENCE = ");
sort(n);
if (pre < head){
for (i = 0; i < uptrack; i++){
printf("%d ", head);
seekcount = seekcount + dist(head, kate[i].up);
head = kate[i].up;
}
for (i = downtrack - 1; i > 0; i--){
printf("%d ", head);
seekcount = seekcount + dist(head, kate[i].down);
head = kate[i].down;
}
}
else{
for (i = downtrack - 1; i >= 0; i--){
printf("%d ", head);
seekcount = seekcount + dist(head, kate[i].down);
head = kate[i].down;
}
for (i = 0; i < uptrack - 1; i++){
printf("%d ", head);
seekcount = seekcount + dist(head, kate[i].up);
head = kate[i].up;
}
}
printf(" %dnTOTAL DISTANCE :%d", head, seekcount);
}
int main(){
int n, i;
printf("ENTER THE DISK SIZE :n");
scanf("%d", &SIZE);
printf("ENTER THE NO OF REQUEST SEQUENCE :n");
scanf("%d", &n);
printf("ENTER THE REQUEST SEQUENCE :n");
for (i = 0; i < n; i++)
scanf("%d", &request[i]);
printf("ENTER THE CURRENT HEAD :n");
scanf("%d", &head);
request[n] = head;
request[n + 1] = SIZE - 1;
request[n + 2] = 0;
printf("ENTER THE PRE REQUEST :n");
scanf("%d", &pre);
scan(n + 3);
}
Output:

More Related Content

PPTX
BLOCK DIAGRAM OF HARDWIRED CONTROL UNIT
PPTX
Direct linking loaders
PPTX
Chat Application - Requirements Analysis & Design
PPTX
University online course registration system
PDF
exam-registration-system.pdf very best projeect
PDF
Sample SRS format
PPT
Airline reservation system 1
PDF
.Net and Windows Application Project on Hotel Management
BLOCK DIAGRAM OF HARDWIRED CONTROL UNIT
Direct linking loaders
Chat Application - Requirements Analysis & Design
University online course registration system
exam-registration-system.pdf very best projeect
Sample SRS format
Airline reservation system 1
.Net and Windows Application Project on Hotel Management

What's hot (20)

DOCX
Software Requirements Specification Final
PPTX
design of accumlator
DOCX
Student management system analysis document
PPTX
OS UNIT 1 PPT.pptx
PPTX
Context free grammar
PPTX
Arduino and c programming
PPT
5 STM32's TIMER.ppt
DOCX
Project for Student Result System
PPTX
Student Result
DOCX
student management system.docx
PPTX
8257 DMA Controller
PDF
Smart application for ams using face recognition
PDF
Unit 3
PPSX
Course Registration System-Problem Statement, SRS,ERD, DFD, Structured Chart
PPT
Slides chapter 8
PPTX
Instruction Execution Cycle
PDF
09.project hospital management system
PPT
Intro to cao &store program
PPT
Microprocessor & microcontroller
PPTX
Operand and Opcode | Computer Science
Software Requirements Specification Final
design of accumlator
Student management system analysis document
OS UNIT 1 PPT.pptx
Context free grammar
Arduino and c programming
5 STM32's TIMER.ppt
Project for Student Result System
Student Result
student management system.docx
8257 DMA Controller
Smart application for ams using face recognition
Unit 3
Course Registration System-Problem Statement, SRS,ERD, DFD, Structured Chart
Slides chapter 8
Instruction Execution Cycle
09.project hospital management system
Intro to cao &store program
Microprocessor & microcontroller
Operand and Opcode | Computer Science
Ad

Similar to OS lab manual1234512345123451234512345.pdf (20)

PDF
Lab Manual_Machine Ldddddddddddddddddearning.pdf
PPT
Nba msr
PDF
Dbms lab manual
PDF
Final 22POP13 Lab Manual- By SBL & PK.pdf
PDF
Expection Setting-1st ppt-Reshma.pdfjjkk
PDF
Te computer-syllabus-2015-course-3-4-17
PDF
Ade manual with co po-18scheme
PPTX
NEP 2020 - National Education Policy 2020
PPTX
OPERATING SYSTEM PPT ON INTRODUCTION AND BASICS
PPTX
Presentation on po pshjhhjhekhhkkhkhjpeo
PDF
B.tech mae-2011-c
PPTX
Introductory PPT CSC202 SECURITY ARCHITECTURE.pptx
DOCX
SE-LAB-Manual.docx of software engineering
PDF
Web Technology LAB MANUAL for Undergraduate Programs
DOCX
AI_LAB_Manual in c with all the programs
PPTX
Course Outcomes and Program Outcomes (POs) ATTAINMENT PROCESS.pptx
PDF
Te computer syllabus 2015 course 3-4-17 3-5-17
PPT
BCS302- Digital Design and computer organization -VTU-2022 scheme-Expectation...
PDF
ds_mod1.pdf
PDF
PPS Manual_AY_2021-22 I & II Sem.pdf
Lab Manual_Machine Ldddddddddddddddddearning.pdf
Nba msr
Dbms lab manual
Final 22POP13 Lab Manual- By SBL & PK.pdf
Expection Setting-1st ppt-Reshma.pdfjjkk
Te computer-syllabus-2015-course-3-4-17
Ade manual with co po-18scheme
NEP 2020 - National Education Policy 2020
OPERATING SYSTEM PPT ON INTRODUCTION AND BASICS
Presentation on po pshjhhjhekhhkkhkhjpeo
B.tech mae-2011-c
Introductory PPT CSC202 SECURITY ARCHITECTURE.pptx
SE-LAB-Manual.docx of software engineering
Web Technology LAB MANUAL for Undergraduate Programs
AI_LAB_Manual in c with all the programs
Course Outcomes and Program Outcomes (POs) ATTAINMENT PROCESS.pptx
Te computer syllabus 2015 course 3-4-17 3-5-17
BCS302- Digital Design and computer organization -VTU-2022 scheme-Expectation...
ds_mod1.pdf
PPS Manual_AY_2021-22 I & II Sem.pdf
Ad

Recently uploaded (20)

PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Cell Types and Its function , kingdom of life
PDF
RMMM.pdf make it easy to upload and study
PDF
advance database management system book.pdf
PPTX
Lesson notes of climatology university.
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Trump Administration's workforce development strategy
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Classroom Observation Tools for Teachers
PPTX
History, Philosophy and sociology of education (1).pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Orientation - ARALprogram of Deped to the Parents.pptx
Final Presentation General Medicine 03-08-2024.pptx
Computing-Curriculum for Schools in Ghana
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Cell Types and Its function , kingdom of life
RMMM.pdf make it easy to upload and study
advance database management system book.pdf
Lesson notes of climatology university.
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Trump Administration's workforce development strategy
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
A powerpoint presentation on the Revised K-10 Science Shaping Paper
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Final Presentation General Medicine 03-08-2024.pptx
Classroom Observation Tools for Teachers
History, Philosophy and sociology of education (1).pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Unit 4 Skeletal System.ppt.pptxopresentatiom

OS lab manual1234512345123451234512345.pdf

  • 1. TELEGRAM : CLICK HERE WHATSAPP : CLICK HERE
  • 2. Academic Year: 2023-24 LABORATORY MANUAL SEMESTER : III SUBJECT : Operating Systems SUBCODE : BCS 303 NAME: ____________________________________________________________ USN: _____________________________________________________________ SECTION: __________________________________________________________ BATCH: ___________________________________________________________
  • 3. PROGRAM OUTCOMES Engineering Graduates will able to: Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering problems. Problem analysis: Identify, formulate, review research literature, and analyse complex engineering problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences. Design/development of solutions: Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural, societal, and environmental considerations. Conduct investigations of complex problems: Use research-based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modelling to complex engineering activities with an understanding of the limitations. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice. Environment and sustainability: Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. Communication: Communicate effectively on complex engineering activities with the engineering community and with society at large, such as, being able to comprehend and write effective reports and design documentation, make effective presentations, and give and receive clear instructions. Project management and finance: Demonstrate knowledge and understanding of the Engineering and management principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in multidisciplinary environments. Life -long learning: Recognize the need for and have the preparation and ability to engage in independent and life -long learning in the broadest context of technological change.
  • 4. INSTITUTE VISION AND MISSION VISION The East Point College of Engineering and Technology aspires to be a globally acclaimed institution, recognized for excellence in engineering education, applied research and nurturing students for holistic development. MISSION M1: To create engineering graduates through quality education and to nurture innovation, creativity and excellence in teaching, learning and research M2: To serve the technical, scientific, economic and societal developmental needs of our communities M3: To induce integrity, teamwork, critical thinking, personality development and ethics in students and to lay the foundation for lifelong learning
  • 5. DEPARTMENT VISION AND MISSION VISION The department orients towards identifying and exploring emerging global trends in the fields of Artificial Intelligence and Data Science through academic excellence and quality research, producing proficient professionals for a flourishing society. MISSION M1: To nurture students with quality education, life-long learning, values and ethics. M2: To produce ethical and competent professionals through comprehensive and holistic methodologies that align with the global industry demands in Artificial Intelligence and Data Science. PROGRAM EDUCATIONAL OBJECTIVES (PEOs) 1. Graduates will possess the ability to apply their knowledge of fundamental engineering, Computer Science and Data Science. 2. Graduates will have sound intercommunication skills, ethical values and responsibilities to work and serve for the development of the society. 3. Graduates will be able to understand, interpret, model and implement the Artificial Intelligence and Data Science based solutions for real world problems. PROGRAM SPECIFIC OUTCOMES (PSOs) 1. To cater and enhance the analytical and technical skills of the graduates in order to be ready for the professional development, research and pursue higher education. 2. To formulate solutions for the real-world problems with the application of Data Science. Department of Computer science and Engg. basic engineering principles and technical skills of Artificial Intelligence and
  • 6. COURSE LEARNING OBJECTIVES • To Demonstrate the need for OS and different types of OS • To discuss suitable techniques for management of different resources • To demonstrate different APIs/Commands related to processor, memory, storage and file system management. COURSE OUTCOMES CO1: Explain the structure and functionality of operating system CO2: Apply appropriate CPU scheduling algorithms for the given problem. CO3: Analyze the various techniques for process synchronization and deadlock handling. CO4: Apply the various techniques for memory management CO5: Explain file and secondary storage management strategies. CO6: Describe the need for information protection mechanisms
  • 7. Sl.N O Experiments 1 Develop a c program to implement the Process system calls (fork (), exec(), wait(), create process, terminate process) 2 Simulate the following CPU scheduling algorithms to find turnaround time and waiting time a) FCFS b) SJF c) Round Robin d) Priority. 3 Develop a C program to simulate producer-consumer problem using semaphores. 4 Develop a C program which demonstrates interprocess communication between a reader process and a writer process. Use mkfifo, open, read, write and close APIs in your program. 5 Develop a C program to simulate Bankers Algorithm for DeadLock Avoidance. 6 Develop a C program to simulate the following contiguous memory allocation Techniques: a) Worst fit b) Best fit c) First fit. 7 Develop a C program to simulate page replacement algorithms: a) FIFO b) LRU 8 Simulate following File Organization Techniques a) Single level directory b) Two level directory 9 Develop a C program to simulate the Linked file allocation strategies. 10 Develop a C program to simulate SCAN disk scheduling algorithm. Course outcomes (Course Skill Set): At the end of the course, the student will be able to: CO 1. Explain the structure and functionality of operating system CO 2. Apply appropriate CPU scheduling algorithms for the given problem. CO 3. Analyse the various techniques for process synchronization and deadlock handling. CO 4. Apply the various techniques for memory management CO 5. Explain file and secondary storage management strategies. CO 6. Describe the need for information protection mechanisms Assessment Details (both CIE and SEE) The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End Exam (SEE) is 50%. The minimum passing mark for the CIE is 40% of the maximum marks (20 marks out of 50) and for the SEE minimum passing mark is 35% of the maximum marks (18 out of 50 marks). A student shall be deemed tohave satisfied the academic requirements and earned the credits allotted to each subject/ course if the student secures a minimum of 40% (40 marks out of 100) in the sum total of the CIE (Continuous Internal Evaluation) and SEE (Semester End Examination) taken together. CIE for the theory component of the IPCC (maximum marks 50) ● IPCC means practical portion integrated with the theory of the course. ● CIE marks for the theory component are 25 marks and that for the practical component is 25 marks. ● 25 marks for the theory component are split into 15 marks for two Internal Assessment Tests (Two Tests, each of 15 Marks with 01-hour duration, are to be conducted) and 10 marks for other assessment methods
  • 8. mentioned in 22OB4.2. The first test at the end of 40-50% coverage of the syllabus and the second testafter covering 85-90% of the syllabus. ● Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for the theorycomponent of IPCC (that is for 25 marks). ● The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of IPCC. CIE for the practical component of the IPCC ● 15 marks for the conduction of the experiment and preparation of laboratory record, and 10 marks for the test to be conducted after the completion of all the laboratory sessions. ● On completion of every experiment/program in the laboratory, the students shall be evaluated including viva-voce and marks shall be awarded on the same day. ● The CIE marks awarded in the case of the Practical component shall be based on the continuous evaluationof the laboratory report. Each experiment report can be evaluated for 10 marks. Marks of all experiments’ write-ups are added and scaled down to 15 marks. ● The laboratory test (duration 02/03 hours) after completion of all the experiments shall be conducted for 50 marks and scaled down to 10 marks. ● Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory component of IPCC for 25 marks. ● The student has to secure 40% of 25 marks to qualify in the CIE of the practical component of the IPCC. SEE for IPCC Suggested Learning Resources: Textbooks 1. Abraham Silberschatz, Peter Baer Galvin, Greg Gagne, Operating System Principles 8th edition,Wiley-India, 2015 Reference Books 1. Ann McHoes Ida M Fylnn, Understanding Operating System, Cengage Learning, 6th Edition 2. D.M Dhamdhere, Operating Systems: A Concept Based Approach 3rd Ed, McGraw- Hill, 2013. 3. P.C.P. Bhatt, An Introduction to Operating Systems: Concepts and Practice 4th Edition, PHI(EEE),2014. 4. William Stallings Operating Systems: Internals and Design Principles, 6th Edition, Pearson.
  • 9. Table of Content Sl. No. Content 1 Develop a c program to implement the Process system calls (fork (), exec(), wait(), create process,terminate process) 2 Simulate the following CPU scheduling algorithms to find turnaround time and waiting time a) FCFS b) SJF c) Round Robin d) Priority. 3 Develop a C program to simulate producer-consumer problem using semaphores. 4 Develop a C program which demonstrates interprocess communication between a reader process and a writer process. Use mkfifo, open, read, write and close APIs in your program. 5 Develop a C program to simulate Bankers Algorithm for DeadLock Avoidance. 6 Develop a C program to simulate the following contiguous memory allocation Techniques: a) Worst fit b) Best fit c) First fit. 7 Develop a C program to simulate page replacement algorithms: a) FIFO b) LRU 8 Simulate following File Organization Techniques a) Single level directory b) Two level directory 9 Develop a C program to simulate the Linked file allocation strategies. 10 Develop a C program to simulate SCAN disk scheduling algorithm.
  • 10. Program-1 Develop a c program to implement the Process system calls (fork (), exec (), wait (), create process,terminate process) #include<stdio.h> // printf() #include<stdlib.h> // exit() #include<sys/types.h> // pid_t #include<sys/wait.h> // wait() #include<unistd.h> // fork int main(int argc, char **argv) { pid_t pid; pid = fork(); if(pid==0) { printf("It is the child process and pid is %dn",getpid()); int i=0; for(i=0;i<8;i++) { printf("%dn",i); } exit(0); } else if(pid > 0) { printf("It is the parent process and pid is %dn",getpid()); int status; wait(&status); printf("Child is reapedn"); } else { printf("Error in forking..n"); exit(EXIT_FAILURE); } return 0; }
  • 12. Program-2 Simulate the following CPU scheduling algorithms to find turnaround time and waiting time a) FCFS #include<stdio.h> int main() { int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j; printf("Enter total number of processes(maximum 20): "); scanf("%d",&n); printf("nEnter Process Burst Time:n"); for(i=0;i<n;i++) { printf("P[%d]: ",i+1); scanf("%d",&bt[i]); } wt[0]=0; for(i=1;i<n;i++) { wt[i]=0; for(j=0;j<i;j++) wt[i]+=bt[j]; } printf("nProcessttBurst TimetWaiting TimetTurnaround Time"); //calculating turnaround time for(i=0;i<n;i++) { tat[i]=bt[i]+wt[i]; avwt+=wt[i]; avtat+=tat[i]; printf("nP[%d]tt%dtt%dtt%d",i+1,bt[i],wt[i],tat[i]); } avwt/=i; avtat/=i; printf("nnAverage Waiting Time:%d",avwt); printf("nAverage Turnaround Time:%d",avtat); return 0; }
  • 13. Output: b) SJF #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("Enter number of process: "); scanf("%d",&n); printf("nEnter Burst Time:n"); for(i=0;i<n;i++) { printf("p%d: ",i+1); scanf("%d",&bt[i]); p[i]=i+1; } for(i=0;i<n;i++) { pos=i; for(j=i+1;j<n;j++) { if(bt[j]<bt[pos]) pos=j; } temp=bt[i]; bt[i]=bt[pos]; bt[pos]=temp; temp=p[i]; p[i]=p[pos]; p[pos]=temp; } wt[0]=0; 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("nProcesst Burst Time tWaiting TimetTurnaround Time"); for(i=0;i<n;i++) { tat[i]=bt[i]+wt[i]; total+=tat[i];
  • 14. printf("np%dtt %dtt %dttt%d",p[i],bt[i],wt[i],tat[i]); } avg_tat=(float)total/n; printf("nnAverage Waiting Time=%f",avg_wt); printf("nAverage Turnaround Time=%fn",avg_tat); return 0; } Output: c) Round Robin #include<stdio.h> int main() { int count,j,n,time,remain,flag=0,time_quantum; int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10]; printf("Enter Total Process:t "); scanf("%d",&n); remain=n; for(count=0;count<n;count++) { printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1); scanf("%d",&at[count]); scanf("%d",&bt[count]); rt[count]=bt[count]; } printf("Enter Time Quantum:t"); scanf("%d",&time_quantum); printf("nnProcesst|Turnaround Time|Waiting Timenn"); for(time=0,count=0;remain!=0;) { if(rt[count]<=time_quantum && rt[count]>0) { time+=rt[count]; rt[count]=0;
  • 15. flag=1; } else if(rt[count]>0) { rt[count]-=time_quantum; time+=time_quantum; } if(rt[count]==0 && flag==1) { remain--; printf("P[%d]t|t%dt|t%dn",count+1,time-at[count],time-at[count]-bt[count]); wait_time+=time-at[count]-bt[count]; turnaround_time+=time-at[count]; flag=0; } if(count==n-1) count=0; else if(at[count+1]<=time) count++; else count=0; } printf("nAverage Waiting Time= %fn",wait_time*1.0/n); printf("Avg Turnaround Time = %f",turnaround_time*1.0/n); return 0; } Output:
  • 16. d) Priority #include<stdio.h> int main() { int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat; printf("Enter Total Number of Process:"); scanf("%d",&n); printf("nEnter Burst Time and Priorityn"); for(i=0;i<n;i++) { printf("nP[%d]n",i+1); printf("Burst Time:"); scanf("%d",&bt[i]); printf("Priority:"); scanf("%d",&pr[i]); p[i]=i+1; } for(i=0;i<n;i++) { pos=i; for(j=i+1;j<n;j++) { if(pr[j]<pr[pos]) pos=j; } temp=pr[i]; pr[i]=pr[pos]; pr[pos]=temp; temp=bt[i]; bt[i]=bt[pos]; bt[pos]=temp; temp=p[i]; p[i]=p[pos]; p[pos]=temp; } wt[0]=0; for(i=1;i<n;i++) { wt[i]=0; for(j=0;j<i;j++) wt[i]+=bt[j]; total+=wt[i]; }
  • 17. avg_wt=total/n; total=0; printf("nProcesst Burst Time tWaiting TimetTurnaround Time"); for(i=0;i<n;i++) { tat[i]=bt[i]+wt[i]; total+=tat[i]; printf("nP[%d]tt %dtt %dttt%d",p[i],bt[i],wt[i],tat[i]); } avg_tat=total/n; printf("nnAverage Waiting Time=%d",avg_wt); printf("nAverage Turnaround Time=%dn",avg_tat); return 0; } Output:
  • 18. Program-3 Develop a C program to simulate producer-consumer problem using semaphores. #include<stdio.h> void main() { int buffer[10], bufsize, in, out, produce, consume, choice=0; in = 0; out = 0; bufsize = 10; while(choice !=3) { printf("n 1. Produce t 2. Consume t3. Exit"); printf("n Enter your choice: "); scanf("%d", &choice); switch(choice) { case 1: if((in+1)%bufsize==out) printf("n Buffer is Full"); else { printf("nEnter the value: "); scanf("%d", &produce); buffer[in] = produce; in = (in+1)%bufsize; } break; case 2: if(in == out) printf("nBuffer is Empty"); else { consume = buffer[out]; printf("nThe consumed value is %d", consume); out = (out+1)%bufsize; } break; } } }
  • 20. Program-4 Develop a C program which demonstrates inter-process communication between a reader process and a writer process. Use mkfifo, open, read, write and close APIs in your program. /*Writer Process*/ #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> int main() { int fd; char buf[1024]; /* create the FIFO (named pipe) */ char * myfifo = "/tmp/myfifo"; mkfifo(myfifo, 0666); printf("Run Reader process to read the FIFO Filen"); fd = open(myfifo, O_WRONLY); write(fd,"Hi", sizeof("Hi")); /* write "Hi" to the FIFO */ close(fd); unlink(myfifo); /* remove the FIFO */ return 0; } /* Reader Process*/ #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h> #define MAX_BUF 1024 int main() { int fd; /* A temp FIFO file is not created in reader */ char *myfifo = "/tmp/myfifo"; char buf[MAX_BUF]; /* open, read, and display the message from the FIFO */ fd = open(myfifo, O_RDONLY); read(fd, buf, MAX_BUF); printf("Writer: %sn", buf); close(fd); return 0; }
  • 21. Instructions for Execution: 1. Run Reader Process 2. Then Run Writer Process
  • 22. Program-5 Develop a C program to simulate Bankers Algorithm for DeadLock Avoidance. #include <stdio.h> #include <stdlib.h> int main() { int Max[10][10], need[10][10], alloc[10][10], avail[10], completed[10], safeSequence[10]; int p, r, i, j, process, count; count = 0; printf("Enter the no of processes : "); scanf("%d", &p); for(i = 0; i< p; i++) completed[i] = 0; printf("nnEnter the no of resources : "); scanf("%d", &r); printf("nnEnter the Max Matrix for each process : "); for(i = 0; i < p; i++) { printf("nFor process %d : ", i + 1); for(j = 0; j < r; j++) scanf("%d", &Max[i][j]); } printf("nnEnter the allocation for each process : "); for(i = 0; i < p; i++) { printf("nFor process %d : ",i + 1); for(j = 0; j < r; j++) scanf("%d", &alloc[i][j]); } printf("nnEnter the Available Resources : "); for(i = 0; i < r; i++) scanf("%d", &avail[i]); for(i = 0; i < p; i++) for(j = 0; j < r; j++) need[i][j] = Max[i][j] - alloc[i][j]; do { printf("n Max matrix:tAllocation matrix:n"); for(i = 0; i < p; i++) { for( j = 0; j < r; j++) printf("%d ", Max[i][j]); printf("tt");
  • 23. for( j = 0; j < r; j++) printf("%d ", alloc[i][j]); printf("n"); } process = -1; for(i = 0; i < p; i++) { if(completed[i] == 0)//if not completed { process = i ; for(j = 0; j < r; j++) { if(avail[j] < need[i][j]) { process = -1; break; } } } if(process != -1) break; } if(process != -1) { printf("nProcess %d runs to completion!", process + 1); safeSequence[count] = process + 1; count++; for(j = 0; j < r; j++) { avail[j] += alloc[process][j]; alloc[process][j] = 0; Max[process][j] = 0; completed[process] = 1; } } } while(count != p && process != -1); if(count == p) { printf("nThe system is in a safe state!!n"); printf("Safe Sequence : < "); for( i = 0; i < p; i++) printf("%d ", safeSequence[i]); printf(">n"); } else printf("nThe system is in an unsafe state!!"); }
  • 25. Program-6 Develop a C program to simulate the following contiguous memory allocation Techniques a) Worst fit #include<stdio.h> int main() { int fragments[10], blocks[10], files[10]; int m, n, number_of_blocks, number_of_files, temp, top = 0; static int block_arr[10], file_arr[10]; printf("nEnter the Total Number of Blocks:t"); scanf("%d",&number_of_blocks); printf("Enter the Total Number of Files:t"); scanf("%d",&number_of_files); printf("nEnter the Size of the Blocks:n"); for(m = 0; m < number_of_blocks; m++) { printf("Block No.[%d]:t", m + 1); scanf("%d", &blocks[m]); } printf("Enter the Size of the Files:n"); for(m = 0; m < number_of_files; m++) { printf("File No.[%d]:t", m + 1); scanf("%d", &files[m]); } for(m = 0; m < number_of_files; m++) { for(n = 0; n < number_of_blocks; n++) { if(block_arr[n] != 1) { temp = blocks[n] - files[m]; if(temp >= 0) { if(top < temp) { file_arr[m] = n; top = temp; } } } fragments[m] = top; block_arr[file_arr[m]] = 1; top = 0; } } printf("nFile NumbertFile SizetBlock NumbertBlock SizetFragment"); for(m = 0; m < number_of_files; m++) { printf("n%dtt%dtt%dtt%dtt%d", m, files[m], file_arr[m], blocks[file_arr[m]], fragments[m]); } printf("n");
  • 26. return 0; } Output: b) Best Fit #include<stdio.h> void main() { int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999; static int barray[20],parray[20]; printf("ntttMemory Management Scheme - Best Fit"); printf("nEnter the number of blocks:"); scanf("%d",&nb); printf("Enter the number of processes:"); scanf("%d",&np); printf("nEnter the size of the blocks:-n"); for(i=1;i<=nb;i++) { printf("Block no.%d:",i); scanf("%d",&b[i]); } printf("nEnter the size of the processes :-n"); for(i=1;i<=np;i++) { printf("Process no.%d:",i); scanf("%d",&p[i]); } for(i=1;i<=np;i++) {
  • 28. c) First Fit #include<stdio.h> #define max 25 void main() { int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0; static int bf[max],ff[max]; printf("ntMemory Management Scheme - First Fit"); printf("nEnter the number of blocks:"); scanf("%d",&nb); printf("Enter the number of files:"); scanf("%d",&nf); printf("nEnter the size of the blocks:-n"); for(i=1;i<=nb;i++) { printf("Block %d:",i); scanf("%d",&b[i]); } printf("Enter the size of the files :-n"); 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++) { if(bf[j]!=1) //if bf[j] is not allocated { 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%dtt%dtt%dtt%dtt%d", i,f[i],ff[i],b[ff[i]],frag[i]); }
  • 30. Program-7 Develop a C program to simulate page replacement algorithms a) 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:n"); scanf("%d",&n); printf("n ENTER THE PAGE NUMBER :n"); 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 stringt page framesn"); for(i=1;i<=n;i++) { printf("%dtt",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("%dt",frame[k]); } printf("n"); } printf("Page Fault Is %d",count); return 0; }
  • 31. Output: b) LRU #include<stdio.h> int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1; int recent[10],lrucal[50],count=0; int lruvictim(); void main() { printf("nttt LRU PAGE REPLACEMENT ALGORITHM"); printf("n Enter no.of Frames...."); scanf("%d",&nof); printf(" Enter no.of reference string.."); scanf("%d",&nor); printf("n Enter reference string.."); for(i=0;i<nor;i++) scanf("%d",&ref[i]); printf("nntt LRU PAGE REPLACEMENT ALGORITHM "); printf("nt The given reference string:"); printf("n……………………………….."); for(i=0;i<nor;i++) printf("%4d",ref[i]); for(i=1;i<=nof;i++) { frm[i]=-1; lrucal[i]=0; } for(i=0;i<10;i++) recent[i]=0; printf("n"); for(i=0;i<nor;i++) { flag=0;
  • 32. printf("nt Reference NO %d->t",ref[i]); for(j=0;j<nof;j++) { if(frm[j]==ref[i]) { flag=1; break; } } if(flag==0) { count++; if(count<=nof) victim++; else victim=lruvictim(); pf++; frm[victim]=ref[i]; for(j=0;j<nof;j++) printf("%4d",frm[j]); } recent[ref[i]]=i; } printf("nnt No.of page faults...%d",pf); } int lruvictim() { int i,j,temp1,temp2; for(i=0;i<nof;i++) { temp1=frm[i]; lrucal[i]=recent[temp1]; } temp2=lrucal[0]; for(j=1;j<nof;j++) { if(temp2>lrucal[j]) temp2=lrucal[j]; } for(i=0;i<nof;i++) if(ref[temp2]==frm[i]) return i; return 0; }
  • 34. Program-8 Simulate following File Organization Techniques a) Single level directory #include<stdlib.h> #include<string.h> #include<stdio.h> struct { char dname[10],fname[10][10]; int fcnt; }dir; void main() { int i,ch; char f[30]; dir.fcnt = 0; printf("nEnter name of directory -- "); scanf("%s", dir.dname); while(1) { printf("nn1. Create Filet2. Delete Filet3. Search File n 4. Display Filest5. ExitnEnter your choice -- "); scanf("%d",&ch); switch(ch) { case 1: printf("nEnter the name of the file -- "); scanf("%s",dir.fname[dir.fcnt]); dir.fcnt++; break; case 2: printf("nEnter the name of the file -- "); scanf("%s",f); for(i=0;i<dir.fcnt;i++) { if(strcmp(f, dir.fname[i])==0) { printf("File %s is deleted ",f); strcpy(dir.fname[i],dir.fname[dir.fcnt-1]); break; } } if(i==dir.fcnt) printf("File %s not found",f); else dir.fcnt--; break; case 3: printf("nEnter the name of the file -- "); scanf("%s",f); for(i=0;i<dir.fcnt;i++) { if(strcmp(f, dir.fname[i])==0) { printf("File %s is found ", f); break; } } if(i==dir.fcnt)
  • 35. printf("File %s not found",f); break; case 4: if(dir.fcnt==0) printf("nDirectory Empty"); else { printf("nThe Files are -- "); for(i=0;i<dir.fcnt;i++) printf("t%s",dir.fname[i]); } break; default: exit(0); } } } Output:
  • 36. b) Two-Level Directory #include<string.h> #include<stdlib.h> #include<stdio.h> struct { char dname[10],fname[10][10]; int fcnt; }dir[10]; void main() { int i,ch,dcnt,k; char f[30], d[30]; dcnt=0; while(1) { printf("nn1. Create Directoryt2. Create Filet3. Delete File"); printf("n4. Search Filett5. Displayt6. ExittEnter your choice -- "); scanf("%d",&ch); switch(ch) { case 1: printf("nEnter name of directory -- "); scanf("%s", dir[dcnt].dname); dir[dcnt].fcnt=0; dcnt++; printf("Directory created"); break; case 2: printf("nEnter name of the directory -- "); scanf("%s",d); for(i=0;i<dcnt;i++) if(strcmp(d,dir[i].dname)==0) { printf("Enter name of the file -- "); scanf("%s",dir[i].fname[dir[i].fcnt]); printf("File created"); break; } if(i==dcnt) printf("Directory %s not found",d); break; case 3: printf("nEnter name of the directory -- "); scanf("%s",d); for(i=0;i<dcnt;i++) { if(strcmp(d,dir[i].dname)==0) { printf("Enter name of the file -- "); scanf("%s",f); for(k=0;k<dir[i].fcnt;k++) { if(strcmp(f, dir[i].fname[k])==0) { printf("File %s is deleted ",f); dir[i].fcnt--;
  • 37. strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]); goto jmp; } } printf("File %s not found",f); goto jmp; } } printf("Directory %s not found",d); jmp : break; case 4: printf("nEnter name of the directory -- "); scanf("%s",d); for(i=0;i<dcnt;i++) { if(strcmp(d,dir[i].dname)==0) { printf("Enter the name of the file -- "); scanf("%s",f); for(k=0;k<dir[i].fcnt;k++) { if(strcmp(f, dir[i].fname[k])==0) { printf("File %s is found ",f); goto jmp1; } } printf("File %s not found",f); goto jmp1; } } printf("Directory %s not found",d); jmp1: break; case 5: if(dcnt==0) printf("nNo Directory's "); else { printf("nDirectorytFiles"); for(i=0;i<dcnt;i++) { printf("n%stt",dir[i].dname); for(k=0;k<dir[i].fcnt;k++) printf("t%s",dir[i].fname[k]); } } break; default:exit(0); } } }
  • 39. Program-9 Develop a C program to simulate the Linked file allocation strategies. #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int f[50], p,i, st, len, j, c, k, a; clrscr(); for(i=0;i<50;i++) f[i]=0; printf("Enter how many blocks already allocated: "); scanf("%d",&p); printf("Enter blocks already allocated: "); for(i=0;i<p;i++) { scanf("%d",&a); f[a]=1; } x: printf("Enter index starting block and length: "); scanf("%d%d", &st,&len); k=len; if(f[st]==0) { for(j=st;j<(st+k);j++) { if(f[j]==0) { f[j]=1; printf("%d-------->%dn",j,f[j]); } else { printf("%d Block is already allocated n",j); k++; } } } else printf("%d starting block is already allocated n",st); printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d", &c); if(c==1) goto x; else exit(0); getch(); }
  • 41. Program-10 Develop a C program to simulate SCAN disk scheduling algorithm. #include <stdio.h> int request[50]; int SIZE; int pre; int head; int uptrack; int downtrack; struct max{ int up; int down; } kate[50]; int dist(int a, int b){ if (a > b) return a - b; return b - a; } void sort(int n){ int i, j; for (i = 0; i < n - 1; i++){ for (j = 0; j < n - i - 1; j++){ if (request[j] > request[j + 1]){ int temp = request[j]; request[j] = request[j + 1]; request[j + 1] = temp; } } } j = 0; i = 0; while (request[i] != head){ kate[j].down = request[i]; j++; i++; } downtrack = j; i++; j = 0; while (i < n){ kate[j].up = request[i]; j++; i++; } uptrack = j; } void scan(int n){ int i; int seekcount = 0; printf("SEEK SEQUENCE = "); sort(n); if (pre < head){ for (i = 0; i < uptrack; i++){
  • 42. printf("%d ", head); seekcount = seekcount + dist(head, kate[i].up); head = kate[i].up; } for (i = downtrack - 1; i > 0; i--){ printf("%d ", head); seekcount = seekcount + dist(head, kate[i].down); head = kate[i].down; } } else{ for (i = downtrack - 1; i >= 0; i--){ printf("%d ", head); seekcount = seekcount + dist(head, kate[i].down); head = kate[i].down; } for (i = 0; i < uptrack - 1; i++){ printf("%d ", head); seekcount = seekcount + dist(head, kate[i].up); head = kate[i].up; } } printf(" %dnTOTAL DISTANCE :%d", head, seekcount); } int main(){ int n, i; printf("ENTER THE DISK SIZE :n"); scanf("%d", &SIZE); printf("ENTER THE NO OF REQUEST SEQUENCE :n"); scanf("%d", &n); printf("ENTER THE REQUEST SEQUENCE :n"); for (i = 0; i < n; i++) scanf("%d", &request[i]); printf("ENTER THE CURRENT HEAD :n"); scanf("%d", &head); request[n] = head; request[n + 1] = SIZE - 1; request[n + 2] = 0; printf("ENTER THE PRE REQUEST :n"); scanf("%d", &pre); scan(n + 3); }