Operating Systems Manual - BCS303
Operating Systems Manual - BCS303
Prof. Dhananjaya M K
Assistant Professor
Reviewed By
Dr.Lokanna Kadakolmath
Approved By
Prof. Kala Venugopal
Head of Department Information Science and Engineering
MISSION OF INSTITUTE
“Acharya Institute of Technology strives to provide excellent academic ambiance to the students
for achieving global standards of technical education, foster intellectual and personal development,
meaningful research and ethical service to sustainable societal needs.”
VISION OF THE DEPARTMENT
“To be center of Academic and Research excellence in the field of Information Technology
inculcating value based education for the development of quality Human Resource”
“Equip students with fundamental concepts, practical knowledge and professional ethics through
dedicated faculty for higher studies and professional career in various Scientific, Engineering and
Technological streams leading to proficiency in the field of Information Technology”
PROGRAM SPECIFIC OUTCOMES (PSOs)
PSO1: Able to apply knowledge of information management and communication systems to provide secured
solutions for real time engineering applications.
PSO2: Apply best software engineering practices, modern tools and technologies to deliver quality products.
The internals marks of lab for 2022 scheme is 15 Marks for Continuous Evaluation and 10 Marks for Lab Internals.
Continuous Evaluation for 2022 scheme:
Sl Parameters Mark 5 4 3 0
No
1. Writing Program/Logic 10 The student is The student is The student has The student is
(present able to write able to write the written not attempted
week’s/previous the program program with incomplete to write
week’s) without any minor logical program with program.
logical and error major logical
syntactical and syntactical
error and error
proper
indentation is
followed.
2. Implementation in the 10 Student is able Student is able Student is The student
target language with to execute, to execute the executed the has not
different inputs debug, and test program, but program executed the
the program for fails to debug, partially(fails to program.
all possible and test the meet desired
inputs/test program for all output)
cases. possible
inputs/test
cases.
Parameters 6 4 2 0 6
3. Record 6 Student Student submits Student fails to The student
submits the the record on submit the does not
record on time time but not record on time. submit the
and, neatly documented record.
documented properly with all
with all possible
possible input/output
input/output samples.
samples.
Parameters 4 4 2 1 0
1.1 OVERVIEW
An Operating System (OS)(as shown in Fig 1) is an interface between a computer user and computer hardware.
An operating system is a software which performs all the basic tasks like file management, memory
management, process management, handling input and output, and controlling peripheral devices such as disk
drives and printers.
Some popular Operating Systems include Linux Operating System, Windows Operating System, VMS, OS/400,
AIX, z/OS, etc. Following are some of important functions of an operating System:
• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Job accounting
Linux is a free and open source operating system and it is a clone version of UNIX operating system. It is open
source as its source code is freely available. It is free to use. Linux was designed considering UNIX
compatibility. Its functionality list is quite similar to that of UNIX.
Hardware layer Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).
Kernel It is the core component of Operating System, interacts directly with hardware, provides low level
services to upper layer components.
The shell takes commands from the user and executes kernel's functions.
Utilities Utility programs that provide the user most of the functionalities of an operating systems.
Kernel
Kernel is the core part of linux. It is responsible for all major activities of this operating system. It consists of
various modules and it interacts directly with the underlying hardware. Kernel provides the required abstraction to
hide low level hardware details to system or application programs.
System Library
System libraries are special functions or programs using which application programs or system utilities accesses
Kernel's features. These libraries implement most of the functionalities of the operating system and do not requires
kernel module's code access rights.
System Utility
Kernel component code executes in a special privileged mode called kernel mode with full access to all resources
of the computer. This code represents a single process, executes in single address space and do not require any
context switch and hence is very efficient and fast. Kernel runs each processes and provides system services to
processes, provides protected access to hardware to processes.
Support code which is not required to run in kernel mode is in System Library. User programs and other system
programs works in User Mode which has no access to system hardware and kernel code. User programs/ utilities
use System libraries to access Kernel functions to get system's low level tasks.
• Open Source Linux source code is freely available and it is community based development project.
Multiple teams work in collaboration to enhance the capability of Linux operating system and it is
continuously evolving.
• Multi User Linux is a multiuser system means multiple users can access system resources like memory/
ram/ application programs at same time.
• Multiprogramming Linux is a multiprogramming system means multiple applications can run at same
time.
• Hierarchical File System Linux provides a standard file structure in which system files/ user files are
arranged.
• Shell Linux provides a special interpreter program which can be used to execute commands of the operating
system. It can be used to do various types of operations, call application programs. etc.
• Security Linux provides user security using authentication features like password protection/ controlled
access to specific files/ encryption of data.
Linux OS Linux could be a free and open supply OS supported operating system standards. It provides
programming interface still as programme compatible with operating system primarily based systems and provides
giant selection applications. A UNIX operating system additionally contains several severally developed parts,
leading to UNIX operating system that is totally compatible and free from proprietary.
Windows OS Windows may be a commissioned OS within which ASCII text file is inaccessible. it’s designed
for the people with the angle of getting no programming information and for business and alternative industrial
users. it‟s terribly straightforward and simple to use.
The distinction between Linux and Windows package is that Linux is completely freed from price whereas
windows is marketable package and is expensive. Associate operating system could be a program meant to regulate
the pc or computer hardware.
Linux is an open supply package wherever users will access the ASCII text file and might improve the code
victimisation the system. On the opposite hand, in windows, users can’t access ASCII text file, and it’s an
authorized OS.
Linux
Linux is a group of open source Unix-like operating systems which was developed by Linus
Torvalds. It is a packaged of Linux distribution. Some of the mostly used Linux distribution are Debian, Fedora
and Ubuntu. It was basically written in C language and assembly language. Kernel used in Linux is Monolithic
kernel. The target systems of Linux distributions are cloud computing, embedded systems, mobile devices,
personal computers, servers, mainframe computers and supercomputers. The first version of Linux was launched
in 1991.
MAC
Linux
Linux is an open source multi-tasking, multi-user operating system. It was initially developed by Linus Torvalds
in 1991. Linux OS is widely used in desktops, mobiles, mainframes etc.
Unix
Unix is multi-tasking, multi-user operating system but is not free to use and is not open source. It was developed
in 1969 by Ken Thompson team at AT&T Bell Labs. It is widely used on servers, workstations etc. Following are
the important differences between Linux and Unix.
Let’s sees that the difference between Linux and windows:
Job scheduling is the process of allocating system resources to many different tasks by an operating system (OS).
The system handles prioritized job queues that are awaiting CPU time and it should determine which job to be
taken from which queue and the amount of time to be allocated for the job.
This type of scheduling makes sure that all jobs are carried out fairly and on time. Most OSs like Unix,
Windows, etc., include standard job-scheduling abilities. A number of programs including database management
systems (DBMS), backup, enterprise resource planning (ERP) and business process management (BPM) feature
specific job scheduling capabilities as well.
1.5 PROCESS MANAGEMENT
Process management involves various tasks like creation, scheduling, termination of processes, and a dead lock.
Process is a program that is under execution, which is an important part of modern-day operating systems. The
OS must allocate resources that enable processes to share and exchange information.
It also protects the resources of each process from other methods and allows synchronization among processes. It
is the job of OS to manage all the running processes of the system. It handles operations by performing tasks like
process scheduling and such as resource allocation.
1.6 PROCESS ARCHITECTURE
Stack The stack stores temporary data like function parameters, returns addresses, and localvariables.
Heap It allocates memory, which may be processed during its run time.
Text It includes the current activity, which is represented by the value of the Program Counter.
Memory management is the functionality of an operating system which handles or manages primary memory and
moves processes back and forth between main memory and disk during execution. Memory management keeps
track of each and every memory location, regardless of either it is allocated to some process or it is free. It checks
how much memory is to be allocated to processes. It decides which process will get memory at what time. It
tracks whenever some memory gets freed or unallocated and correspondingly it updates the status.
The operating system takes care of mapping the logical addresses to physical addresses at the time of memory
allocation to the program. There are three types of addresses used in a program before and after memory is
allocated –
Symbolic addresses
The addresses used in a source code. The variable names, constants, and instruction labels are the basic elements
of the symbolic address space.
Relative addresses
At the time of compilation, a compiler converts symbolic addresses into relative addresses.
Physical addresses
The loader generates these addresses at the time when a program is loaded into main memory.
System call is a mechanism that provides the interface between a process and the operating system. It is a
programmatic method in which a computer program requests a service from the kernel of the OS. System call
offers the services of the operating system to the user programs via API (Application Programming Interface).
System calls are the only entry points for the kernel system. For example, if we need to write a program code to
read data from one file, copy that data into another file.
The first information that the program requires is the name of the two files, the input and output files. In an
interactive system, this type of program execution requires some system calls by OS.
• First call is to write a prompting message on the screen.
• Second, to read from the keyboard, the characters which define the two files.
The operating system is used everywhere nowadays especially such as banks, schools, colleges, universities,
govt. organizations, IT companies, mobile, etc, …
No device can operate without an operating system because it controls all the user’s commands. Linux /unix
operating systems is used in bank because it’s very secure operating systems.
Symbian OS, windows mobile, IOS and Android OS are used in mobile phones operating systems as these
operating systems are a lightweight operating systems.
LABORATORY PROGRAMS
1) Develop a c program to implement the Process system calls (fork (), exec(), wait(), create
process, terminate process) .
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
pid_t child_pid;
int status;
if (child_pid < 0)
{
// Fork failed
perror("Fork failed");
exit(1);
} else if (child_pid == 0)
{
// Child process
printf("Child process (PID: %d) is running.\n", getpid());
if (WIFEXITED(status)) {
printf("Child process (PID: %d) exited with status %d.\n", child_pid, WEXITSTATUS(status));
}
else {
printf("Child process (PID: %d) did not exit normally.\n", child_pid);
}
Information Science & Engineering,AIT Bangalore 17
Opearting Systems Lab Manual(BCS303) 2023-24
}
return 0;
}
OUTPUT:
OUTPUT :
2) Simulate the following CPU scheduling algorithms to find turnaround time and waiting
time a) FCFS b) SJF c) Round Robin d) Priority.
OUTPUT:
OUTPUT :
C) Round Robin
#include<stdio.h>
int main()
{
int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
float awt=0,att=0,temp=0;
printf("Enter the no of processes -- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for process %d -- ", i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnter the size of time slice -- ");
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i])
max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t) {
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else {
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++){
wa[i]=tat[i]-ct[i];
att+=tat[i];
awt+=wa[i];}
printf("\nThe Average Turnaround time is -- %f",att/n);
printf("\nThe Average Waiting time is -- %f ",awt/n);
OUTPUT :
D)Priority
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pri[20],i,j,k,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; //contains process number
}
printf(" enter priority of the process ");
for(i=0;i<n;i++)
{
p[i] = i;
//printf("Priority of Process");
printf("p%d ",i+1);
scanf("%d",&pri[i]);
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(pri[i] > pri[k])
{
temp=p[i];
p[i]=p[k];
p[k]=temp;
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=pri[i];
pri[i]=pri[k];
pri[k]=temp;
}
wt[0]=0; //waiting time for first process will be zero
//calculate waiting time
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; //average waiting time
total=0;
printf("\nProcess\t Burst Time \tPriority \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\np%d\t\t %d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],pri[i],wt[i],tat[i]);
}
avg_tat=(float)total/n; //average turnaround time
printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
}
OUTPUT:
// Initialize a mutex to 1
int mutex = 1;
// Item produced
x++;
printf("\nProducer produces"
"item %d",
x);
// Driver Code
int main()
{
int n, i;
printf("\n1. Press 1 for Producer"
"\n2. Press 2 for Consumer"
"\n3. Press 3 for Exit");
// Switch Cases
switch (n) {
case 1:
if ((mutex == 1)
&& (empty != 0)) {
producer();
}
case 2:
// Exit Condition
case 3:
exit(0);
break;
}
}
}
OUTPUT:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FIFO_PATH "myfifo"
void writerProcess() {
int fd;
char buffer[] = "Hello, Reader!";
void readerProcess() {
int fd;
char buffer[50];
if (fd == -1) {
perror("Error opening FIFO for reading");
exit(EXIT_FAILURE);
}
int main() {
pid_t pid;
return 0;
}
OUTPUT:
int main()
{
int n, m, i, j, k;
n = 5; // Number of processes
m = 3; // Number of resources
{ 2, 0, 0 }, // P1
{ 3, 0, 2 }, // P2
{ 2, 1, 1 }, // P3
{ 0, 0, 2 } }; // P4
{ 3, 2, 2 }, // P1
{ 9, 0, 2 }, // P2
{ 2, 2, 2 }, // P3
{ 4, 3, 3 } }; // P4
f[k] = 0;
int need[n][m];
int y = 0;
if (f[i] == 0) {
int flag = 0;
flag = 1;
break;
if (flag == 0) {
ans[ind++] = i;
avail[y] += alloc[i][y];
f[i] = 1;
}
Information Science & Engineering,AIT Bangalore 35
Opearting Systems Lab Manual(BCS303) 2023-24
int flag = 1;
for(int i=0;i<n;i++)
if(f[i]==0)
flag=0;
break;
if(flag==1)
return (0);
OUTPUT:
ise@ise-HP-Compaq-8200-Elite-MT-PC:~$ ./a.out
A) Worst fit
#include <stdio.h>
#define MAX_BLOCKS 100
struct MemoryBlock
{
int block_id;
int size;
int allocated;
};
blocks[i].allocated = 0;
}
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int processSize;
printf("Enter the size of process %d: ", i + 1);
scanf("%d", &processSize);
worstFit(blocks, m, processSize);
}
return 0;
}
OUTPUT:
B) Best fit
#include <stdio.h>
// Define the maximum number of memory blocks
#define MAX_BLOCKS 100
// Structure to represent memory blocks
struct MemoryBlock {
int block_id;
int size;
int allocated;
};
// Function to perform best-fit memory allocation
void bestFit(struct MemoryBlock blocks[], int m, int processSize) {
int bestIdx = -1;
for (int i = 0; i < m; i++) {
if (blocks[i].allocated == 0 && blocks[i].size >= processSize) {
if (bestIdx == -1 || blocks[i].size < blocks[bestIdx].size) {
bestIdx = i;
}}
}
if (bestIdx != -1) {
// Allocate the memory block
blocks[bestIdx].allocated = 1;
printf("Process with size %d allocated to block %d\n", processSize, bestIdx + 1);
} else {
printf("Cannot allocate the process with size %d\n", processSize);
}
}
int main() {
int m; // Number of memory blocks
printf("Enter the number of memory blocks: ");
scanf("%d", &m);
struct MemoryBlock blocks[MAX_BLOCKS];
for (int i = 0; i < m; i++) {
blocks[i].block_id = i + 1;
printf("Enter the size of memory block %d: ", i + 1);
scanf("%d", &blocks[i].size);
blocks[i].allocated = 0; // Initialize as unallocated
}
int n; // Number of processes
printf("Enter the number of processes: ");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
Information Science & Engineering,AIT Bangalore 40
Opearting Systems Lab Manual(BCS303) 2023-24
int processSize;
printf("Enter the size of process %d: ", i + 1);
scanf("%d", &processSize);
bestFit(blocks, m, processSize);
}
return 0;
}
OUTPUT:
#include <stdio.h>
// Number of memory blocks
#define NUM_BLOCKS 5
// Number of processes
#define NUM_PROCESSES 5
// Sizes of memory blocks
int memory_blocks[NUM_BLOCKS] = {100, 500, 200, 300, 600};
// Sizes of processes
int process_sizes[NUM_PROCESSES] = {212, 417, 112, 426, 112};
// Array to keep track of whether a block is allocated or not
int allocated[NUM_BLOCKS] = {0};
// Function to perform Best Fit memory allocation
void bestFit() {
for (int i = 0; i < NUM_PROCESSES; i++) {
int best_fit_index = -1;
for (int j = 0; j < NUM_BLOCKS; j++) {
if (!allocated[j] && memory_blocks[j] >= process_sizes[i]) {
if (best_fit_index == -1 || memory_blocks[j] < memory_blocks[best_fit_index]) {
best_fit_index = j;
}
}
}
if (best_fit_index != -1) {
allocated[best_fit_index] = 1;
printf("Process %d (size %d) is allocated to Block %d (size %d)\n",
i, process_sizes[i], best_fit_index, memory_blocks[best_fit_index]);
} else {
printf("Process %d (size %d) cannot be allocated\n", i, process_sizes[i]);
}
}
}
int main() {
bestFit();
return 0;
}
OUTPUT:
C. First fit
#include <stdio.h>
// Define the maximum number of memory blocks
#define MAX_BLOCKS 100
// Structure to represent memory blocks
struct MemoryBlock {
int block_id;
int size;
int allocated;
};
// Function to perform first-fit memory allocation
void firstFit(struct MemoryBlock blocks[], int m, int processSize) {
for (int i = 0; i < m; i++) {
if (blocks[i].allocated == 0 && blocks[i].size >= processSize) {
// Allocate the memory block
blocks[i].allocated = 1;
printf("Process with size %d allocated to block %d\n", processSize, i + 1);
return;
}
}
printf("Cannot allocate the process with size %d\n", processSize);
}
int main() {
int m; // Number of memory blocks
printf("Enter the number of memory blocks: ");
scanf("%d", &m);
struct MemoryBlock blocks[MAX_BLOCKS];
for (int i = 0; i < m; i++) {
blocks[i].block_id = i + 1;
Information Science & Engineering,AIT Bangalore 43
Opearting Systems Lab Manual(BCS303) 2023-24
printf("Enter the size of memory block %d: ", i + 1);
scanf("%d", &blocks[i].size);
blocks[i].allocated = 0; // Initialize as unallocated
}
int n; // Number of processes
printf("Enter the number of processes: ");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int processSize;
printf("Enter the size of process %d: ", i + 1);
scanf("%d", &processSize);
firstFit(blocks, m, processSize);
}
return 0;
}
OUTPUT:
#include <stdio.h>
int main()
{
int incomingStream[] = {4 , 1 , 2 , 4 , 5,4,1,2,3,6};
int pageFaults = 0;
int frames = 3;
int m, n, s, pages;
pages = sizeof(incomingStream)/sizeof(incomingStream[0]);
printf(" Incoming \t Frame 1 \t Frame 2 \t Frame 3 ");
int temp[ frames ];
for(m = 0; m < frames; m++)
{
temp[m] = -1;
}
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(incomingStream[m] == temp[n])
{
s++;
pageFaults--;
}
}
pageFaults++;
OUTPUT:
B) LRU
#include<stdio.h>
#include<limits.h>
int checkHit(int incomingPage, int queue[], int occupied){
return 0;
}
void printFrame(int queue[], int occupied)
{
for(int i = 0; i < occupied; i++)
printf("%d\t\t\t",queue[i]);
}
int main()
{
// int incomingStream[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1};
// int incomingStream[] = {1, 2, 3, 2, 1, 5, 2, 1, 6, 2, 5, 6, 3, 1, 3, 6, 1, 2, 4, 3};
int incomingStream[] = {1, 2, 3, 2, 1, 5, 2, 1, 6, 2, 5, 6, 3, 1, 3};
int n = sizeof(incomingStream)/sizeof(incomingStream[0]);
int frames = 3;
int queue[n];
int distance[n];
int occupied = 0;
int pagefault = 0;
printFrame(queue, occupied);
}
else{
printf("\n");
}
return 0;
}
OUTPUT:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Maximum number of files in the directory
#define MAX_FILES 100
// Maximum file name length
#define MAX_NAME_LENGTH 256
// File structure to represent files
typedef struct File {
char name[MAX_NAME_LENGTH];
int size;
char content[1024]; // For simplicity, we use a fixed content size
} File;
// Directory structure to hold files
typedef struct Directory {
File files[MAX_FILES];
int num_files;
} Directory;
// Function to create a new file
File createFile(const char* name, int size, const char* content)
{
File newFile;
strncpy(newFile.name, name, MAX_NAME_LENGTH);
newFile.size = size;
strncpy(newFile.content, content, sizeof(newFile.content));
return newFile;
}
// Function to add a file to the directory
void addFileToDirectory(Directory* directory, File file) {
if (directory->num_files < MAX_FILES) {
directory->files[directory->num_files] = file;
directory->num_files++;
} else {
printf("Directory is full. Cannot add more files.\n");
}
}
// Function to display the contents of the directory
void displayDirectoryContents(const Directory* directory) {
printf("Directory Contents:\n");
for (int i = 0; i < directory->num_files; i++) {
printf("File: %s, Size: %d\n", directory->files[i].name, directory->files[i].size);
}
}
Information Science & Engineering,AIT Bangalore 50
Opearting Systems Lab Manual(BCS303) 2023-24
int main() {
Directory directory;
directory.num_files = 0;
OUTPUT :
directories[i].files[directories[i].num_files].content[0] = '\0';
directories[i].num_files++;
num_dirs++;
printf("Directory %s created in %s.\n", dir_name, parent_name);
return;
}
}
printf("Error: Parent directory not found.\n");
}
void createFile(char dir_name[], char file_name[]) {
for (int i = 0; i < num_dirs; i++) {
if (strcmp(directories[i].name, dir_name) == 0) {
if (directories[i].num_files >= MAX_FILES) {
OUTPUT :
OUTPUT :
#include<stdio.h>
#include<stdlib.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");
int pos[] = {90,120,35,122,38,128,65,68};
for(i=1;i<=n;i++)
{
//scanf("%d",&temp);
temp = pos[i-1];
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;
}
}
}
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;
//queue[i+1]=0;
for(i=temp1+1,j=0;j<temp2;i++,j++)
queue[i]=queue2[j];
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: