Opearating System Manual
Opearating System Manual
LABORATORY MANUAL
COURSE: OPERATING SYSTEMS
SEMESTER: III
1. Course Details
Year / Semester 2nd/ 3rd Academic Year 2022-23
Course Title Operating Systems Course Code BCS303
Course Type CIE Marks 50
(Theory/Practical Theory SEE Marks 50
/Integrated ) Total Marks 100
Teaching Hours/Week 3:0:2:0 Duration of SEE 3
(L:T:P:S)
Lab Manual Authors Sign - Date
2. Institute Mission:
To Enrich Students with the essence of science and engineering knowledge, Professional ethics
and social values.
To instill creativity and Research Temperament to Reach the Greater Heights of Professional
Success.
4. Program Objectives: The educational objectives of the Mechanical Engineering Program are to
prepare our graduates to:
PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO2: Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural science, and engineering sciences.
PO3: 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, cultural, societal and environmental considerations.
PO4: Conduct investigations of complex problems: Use of research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with
an understanding of the limitations.
PO6: 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.
Department of CSE(AIML) 3
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL (BCS303)
PO7: 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.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams and in multidisciplinary settings.
PO11: 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.
PO12: 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.
5. Course Objectives
● To demonstrate different APIs/Commands related to processor, memory, storage and file system
Management. .
6. 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
Department of CSE(AIML) 3
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL (BCS303)
7. Assessment Details
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 to have 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 test after 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 theory
component 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 evaluation of 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 Theory SEE will be conducted by University as per the scheduled timetable, with common question papers for
the course (duration 03 hours) 1. The question paper will have ten questions. Each question is set for 20 marks. 2.
There will be 2 questions from each module. Each of the two questions under a module (with a maximum of 3 sub-
questions), should have a mix of topics under that module. 3. The students have to answer 5 full questions, selecting
one full question from each module. 4. Marks scored by the student shall be proportionally scaled down to 50 Marks
The theory portion of the IPCC shall be for both CIE and SEE, whereas the practical portion will have a CIE
component only. Questions mentioned in the SEE paper may include questions from the practical component
Department of CSE(AIML) 3
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
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.
Simulate following File Organization Techniques a) Single level directory b) Two level
8
directory
Department of CSE(AIML) 4
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
1. Develop a C program to implements the Process system calls fork(), exec(), wait(),create
process, terminate process.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
// Create a child process
pid_t pid = fork();
if (pid == 0) {
// Child process
printf("I am the child process!\n");
execlp("/bin/ls", "/bin/ls", NULL); // Replace with the program you want to run
} else if (pid > 0) {
// Parent process
printf("I am the parent process!\n");
wait(NULL); // Wait for the child process to finish
} else {
// Error
perror("fork");
exit(1);
}
return 0;
}
Output
I am the child process!\
I am the parent process!
a.out program1.c program2.c
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
2 .Simulate the following CPU scheduling algorithms to find turnaround time and waiting time
a) FCFS b) SJF c) Round Robin d) Priority.
#include <stdio.h>
// Process structure
struct Process {
int process_id;
int burst_time;
int priority; // For Priority Scheduling
};
waiting_time[0] = 0;
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
// Function to calculate waiting time and turnaround time for Round Robin
void round_robin(struct Process processes[], int n, int quantum, int waiting_time[], int turnaround_time[]) {
int remaining_time[n];
for (int i = 0; i < n; i++) {
remaining_time[i] = processes[i].burst_time;
}
int time = 0;
while (1) {
int done = 1;
if (done == 1) {
break;
}
}
// Function to calculate waiting time and turnaround time for Priority Scheduling
void priority_scheduling(struct Process processes[], int n, int waiting_time[], int turnaround_time[]) {
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (processes[i].priority > processes[j].priority) {
struct Process temp = processes[i];
processes[i] = processes[j];
processes[j] = temp;
}
}
}
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
waiting_time[0] = 0;
int main() {
int n, quantum;
// FCFS
fcfs(processes, n, waiting_time, turnaround_time);
printf("\nFCFS Scheduling:\n");
print_results(processes, n, waiting_time, turnaround_time);
// SJF
sjf(processes, n, waiting_time, turnaround_time);
printf("\nSJF Scheduling:\n");
print_results(processes, n, waiting_time, turnaround_time);
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
// Round Robin
printf("\nEnter time quantum for Round Robin: ");
scanf("%d", &quantum);
round_robin(processes, n, quantum, waiting_time, turnaround_time);
printf("\nRound Robin Scheduling:\n");
print_results(processes, n, waiting_time, turnaround_time);
// Priority Scheduling
priority_scheduling(processes, n, waiting_time, turnaround_time);
printf("\nPriority Scheduling:\n");
print_results(processes, n, waiting_time, turnaround_time);
return 0;
}
Output
Enter the number of processes: 3
Enter burst time for process 1: 24
Enter priority for process 1: 1
Enter burst time for process 2: 3
Enter priority for process 2: 2
Enter burst time for process 3: 3
Enter priority for process 3: 3
FCFS Scheduling:
Process Burst Time Waiting Time Turnaround Time
1 24 0 24
2 3 24 27
3 3 27 30
SJF Scheduling:
Process Burst Time Waiting Time Turnaround Time
2 3 0 3
3 3 3 6
1 24 6 30
Enter time quantum for Round Robin: 4
Round Robin Scheduling:
Process Burst Time Waiting Time Turnaround Time
2 3 0 3
3 3 3 6
1 24 6 30
Priority Scheduling:
Process Burst Time Waiting Time Turnaround Time
1 24 0 24
2 3 24 27
3 3 27 30
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#define BUFFER_SIZE 5
sem_post(&mutex);
sem_post(&full);
}
pthread_exit(NULL);
}
sem_post(&mutex);
sem_post(&empty);
}
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
pthread_exit(NULL);
}
int main() {
pthread_t producer_thread, consumer_thread;
// Initialize semaphores
sem_init(&empty, 0, BUFFER_SIZE);
sem_init(&full, 0, 0);
sem_init(&mutex, 0, 1);
// Destroy semaphores
sem_destroy(&empty);
sem_destroy(&full);
sem_destroy(&mutex);
return 0;
}
Output
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
void writer_process() {
int fd;
char message[] = "Hello, reader!";
void reader_process() {
int fd;
char buffer[50];
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
close(fd);
}
int main() {
pid_t pid;
if (pid == -1) {
perror("fork");
exit(EXIT_FAILURE);
}
if (pid > 0) {
// Parent process (writer)
writer_process();
} else {
// Child process (reader)
reader_process();
}
return 0;
}
Output
Reader received: Hello, reader!
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
#include<stdio.h>
int main() {
/* array will store at most 5 process with 3 resoures if your process or
resources is greater than 5 and 3 then increase the size of array */
int p, c, count = 0, i, j, alc[5][3], max[5][3], need[5][3], safe[5], available[3], done[5], terminate = 0;
printf("Enter the number of process and resources");
scanf("%d %d", & p, & c);
// p is process and c is diffrent resources
printf("enter allocation of resource of all process %dx%d matrix", p, c);
for (i = 0; i < p; i++) {
for (j = 0; j < c; j++) {
scanf("%d", & alc[i][j]);
}
}
printf("enter the max resource process required %dx%d matrix", p, c);
for (i = 0; i < p; i++) {
for (j = 0; j < c; j++) {
scanf("%d", & max[i][j]);
}
}
printf("enter the available resource");
for (i = 0; i < c; i++)
scanf("%d", & available[i]);
}
if (terminate != (p - 1)) {
printf("\n available resource after completion\n");
for (i = 0; i < c; i++) {
printf("%d\t", available[i]);
}
printf("\n safe sequence are\n");
for (i = 0; i < p; i++) {
printf("p%d\t", safe[i]);
}
}
return 0;
}
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
output
Enter the number of process and resources
53
enter allocation of resource of all process 5x3 matrix
010
200
302
211
002
enter the max resource process required 5x3 matrix
753
322
902
422
533
enter the available resource 3 3 2
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
a)WORST-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("\n\tMemory Management Scheme - Worst 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;
}
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
}
}
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]);
}
INPUT
OUTPUT
File No File Size Block No Block Size Fragment
1 1 3 7 6
2 4 1 5 1
b) Best-fit
#include<stdio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
printf("\n\tMemory Management Scheme - Best Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
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)
{
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");
for(i=1;i<=nf && ff[i]!=0;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]);
}
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
OUTPUT
File No File Size Block No Block Size Fragment
1 1 2 2 1
2 4 1 5 1
c) First-fit
#include<stdio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
printf("\n\tMemory 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]);
}
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
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]);
}
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
OUTPUT
File No File Size Block No Block Size Fragment
1 1 1 5 4
2 4 3 7 3
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
Output:
Incoming Frame 1 Frame 2 Frame 3
4 4 - -
1 4 1 -
2 4 1 2
4 4 1 2
5 5 1 2
Total Page Faults: 4
a)LRU
#include<stdio.h>
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++;
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS 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];
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])
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
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
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
8. Simulate following file organization techniques a)single level directory b) two level
directory
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
Output:
Enter the directory name:sss
Enter the number of files:3
Enter file name to be created:aaa
Do you want to enter another file(yes - 1 or no - 0):1
Enter file name to be created:bbb
Do you want to enter another file(yes - 1 or no - 0):1
Enter file name to be created:ccc
Do you want to enter another file(yes - 1 or no - 0):0
Directory name is:sss
Files names are:
aaa
bbb
ccc
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
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++)
{
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
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("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
{
printf("\n%s\t\t",dir[i].dname);
for(k=0;k<dir[i].fcnt;k++)
printf("\t%s",dir[i].fname[k]);
}
}
break;
default:exit(0);
}
}
}
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
Output:
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 1
Directory files
Directory Files
Aiml os
java
cse cg
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
output
Enter how many blocks to be allocated: 3
Enter blocks already allocated: 1 3 5
Enter index starting block and length: 2 2
2-------->1
3 Block is already allocated
4-------->1
Do you want to enter more file(Yes - 1/No - 0)0
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
#include<stdio.h>
int main()
{
int queue[20],n,head,i,j,k,seek=0,max,diff,temp,queue1[20],queue2[20],
temp1=0,temp2=0;
float avg;
printf("Enter the max range of disk\n");
scanf("%d",&max);
printf("Enter the initial head position\n");
scanf("%d",&head);
printf("Enter the size of queue request\n");
scanf("%d",&n);
printf("Enter the queue of disk positions to be read\n");
for(i=1;i<=n;i++)
{
scanf("%d",&temp);
if(temp>=head)
{
queue1[temp1]=temp;
temp1++;
}
else
{
queue2[temp2]=temp;
temp2++;
}
}
for(i=0;i<temp1-1;i++)
{
for(j=i+1;j<temp1;j++)
{
if(queue1[i]>queue1[j])
{
temp=queue1[i];
queue1[i]=queue1[j];
queue1[j]=temp;
}
}
}
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
for(i=0;i<temp2-1;i++)
{
for(j=i+1;j<temp2;j++)
{
if(queue2[i]<queue2[j])
{
temp=queue2[i];
queue2[i]=queue2[j];
queue2[j]=temp;
}
}
}
for(i=1,j=0;j<temp1;i++,j++)
queue[i]=queue1[j];
queue[i]=max;
for(i=temp1+2,j=0;j<temp2;i++,j++)
queue[i]=queue2[j];
queue[i]=0;
queue[0]=head;
for(j=0;j<=n+1;j++)
{
diff=abs(queue[j+1]-queue[j]);
seek+=diff;
printf("Disk head moves from %d to %d with seek
%d\n",queue[j],queue[j+1],diff);
}
printf("Total seek time is %d\n",seek);
avg=seek/(float)n;
printf("Average seek time is %f\n",avg);
return 0;
}
Output
Enter the max range of disk
200
Enter the initial head position
53
Enter the size of queue request
8
Enter the queue of disk positions to be read
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur
OPERATING SYSTEMS LAB MANUAL
98
183
37
122
14
124
65
67
Disk head moves from 53 to 65 with seek
12
Disk head moves from 65 to 67 with seek
2
Disk head moves from 67 to 98 with seek
31
Disk head moves from 98 to 122 with seek
24
Disk head moves from 122 to 124 with seek
2
Disk head moves from 124 to 183 with seek
59
Disk head moves from 183 to 200 with seek
17
Disk head moves from 200 to 37 with seek
163
Disk head moves from 37 to 14 with seek
23
Disk head moves from 14 to 0 with seek
14
Total seek time is 347
Average seek time is 43.375000
Department of CSE(AIML) 36
BLDEA’s V P Dr PGHCET, Vijayapur