Professional Documents
Culture Documents
Laboratory Manual
(Student Copy)
Vision
To be a premier institution of technical education;
always aiming at becoming a valuable resource for
industry and society.
Mission
To provide technologically inspiring environment
for learning.
To promote creativity, innovation and professional
activities.
To inculcate ethical and moral values.
To cater personal, professional and societal needs
through quality education.
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
Department Vision:
To evolve as a centre of excellence in the field of Computer Engineering to
cater to industrial and societal needs.
Department Mission:
To provide quality technical education with the aid of modern resources.
Inculcate creative thinking through innovative ideas and project
development.
To encourage life-long learning, leadership skills, entrepreneurship skills
with ethical & moral values.
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.
Course Objectives
Course Outcomes
At the end of the course student will be able to: Action verb Bloom Level
Course Outcomes
Experiment CSL704.
CSL704.2 CSL704.3 CSL704.4
1
Representation of Various Robots and their
specification 3 - -- -
Coordinate Transformation - 3 - -
Fundamental Rotation
- 3 - -
Composite Rotation
- 3 - -
Homogenous Transformation - 3 - -
INDEX
Sr.
Name of Experiment D.O.P. D.O.C. Page No. Remark
No.
CPU-OS Simulator.
Implement deadlock detection and
7 16/4/2021 23/4/2021
avoidance using Banker’s algorithm.
Implement memory allocation
8 23/4/2021 30/4/2021
strategy First fit.
Implement page replacement policy
9 30/4/2021 7/5/2021
LRU.
Implement disk scheduling
10 7/5/2021 10/5/2021
algorithms FCFS, SSTF.
Experiment No.1
Explore the internal and external commands of Linux.
Date of Performance:
Date of Submission:
Internal Commands : Commands which are built into the shell. For all the shell built-in
commands, execution of the same is fast in the sense that the shell doesn’t have to search
the given path for them in the PATH variable, and also no process needs to be spawned
for executing it.
Examples: source, cd, fg, etc.
External Commands : Commands which aren’t built into the shell. When an external
command has to be executed, the shell looks for its path given in the PATH variable, and
also a new process has to be spawned and the command gets executed. They are usually
located in /bin or /usr/bin. For example, when you execute the “cat” command, which
usually is at /usr/bin, the executable /usr/bin/cat gets executed.
Examples: ls, cat etc.
pwd : It gives absolute path to your current location i.e. current working directory.
napster@napster-Veriton-Series:~$ pwd
/home/napster
napster@napster-Veriton-Series:~/TRIAL$ ls
hello.txt TRIAL2
cat : 1) It can also use to create new file with content as shown below.
cat> hello.txt
hello from Shamika
2) It can also use to append the data into existing file as shown below.
cat>>hello.txt
How are you?
3) It is used to concatenate files.
napster@napster-Veriton-Series:~/TRIAL$ cat hello.txt hi.txt
hello from Shamika
How are you?
Welcome to Os Lab.
b1@comp:~$ cat > a
Apple
mango is also a fruit
^C
b1@comp:~$ cat a
Apple
mango is also a fruit
APPENDING
mv: To rename a file from source to destination and To move file from one location to
other location.
grep: It searches all text files in the current directory for lines containing “hello”
napster@napster-Veriton-Series:~/TRIAL$ grep hello *.txt
hello from Shamika
date: Print or set the system date and time ,Display the current time in the given
FORMAT, or set the system date.
b1@comp:~$ date
Fri Feb 16 15:43:44 IST 2018
time: Displays time of the system.
wc : print newline, word, and byte counts for each file, Print newline, word, and byte counts
for each FILE, and a total line if more than one FILE is specified.
b1@comp:~$ wc a
6 11 57 a
chmod - change file mode bits
chmod changes the file mode bits of each given file according to mode, which can be
either a symbolic representation of changes to make, or an octal number
representing the bit pattern for the new mode bits.
b1@comp:~$ chmod 777 a
b1@comp:~$ ls -l a
-rw-rw-r-- 1 b1 b1 57 Feb 16 15:44 a
chown - change file owner and group
chown changes the user and/or group ownership of each given file. If only an owner (a
user name or numeric user ID) is given, that user is made the owner of each given file, and
the files' group is not changed. If the owner is followed by a colon and a group name (or
numeric group ID), with no spaces between them, the group ownership of the files is
changed as well.
b1@comp:~$ sudo chown root:root a
b1@comp:~$ ls -l a
umask - set file mode creation mask , umask() sets the calling process's file mode creation
mask (umask) to mask & 0777 (i.e., only the file permission bits of mask are used), and
returns the previous value of the mask.
b1@comp:~$ umask -S
u=rwx,g=rwx,o=rx
Experiment No. 2
Explore User Management commands of Linux.
Date of Performance:
Date of Submission:
Objective: Since Linux is a multi-user operating system, several people may be logged in
and actively working on a given machine at the same time. Security-wise, it is never a good
idea to allow users to share the credentials of the same account. In fact, best practices dictate
the use of as many user accounts as people needing access to the machine.
At the same time, it is to be expected that two or more users may need to share access to
certain system resources, such as directories and files. User and group management in Linux
allows us to accomplish both objectives.
Theory:
useradd - create a new user or update default new user information ,useradd is a low level
utility for adding users.
userdel - delete a user account and related files
groupadd - create a new group , The groupadd command creates a new group account using
the values specified on the command line plus the default values from the system. The new
group will be entered into the system files as needed.
groupdel - delete a group , The groupdel command modifies the system account files,
deleting all
entries that refer to GROUP. The named group must exist
who - show who is logged on , Print information about users who are currently logged in.
whoami - print effective userid
passwd - change user password
The passwd command changes passwords for user accounts. A normal user may only change
the password for his/her own account, while the superuser may change the password for any
account. passwd also changes the account or associated password validity period.
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
Code:
b1@comp:~$ ls -l a
-rwxrwxrwx 1 b1 b1 72 Feb 16 16:09 a
b1@comp:~$ who
b1 :0 2018-02-16 15:37 (:0)
b1 pts/0 2018-02-16 16:16 (:0)
b1@comp:~$ whoami
b1
Conclusion: Comment on the role of user and group management commands of Linux.
Theory:
Shell is a user program or its environment is provided for user interaction. It is a command
prompt within Linux where you can type commands. It is a program that takes your
commands from the keyboard and gives them to the OS to perform. Shell is not part of
system KERNAL but it uses system KERNAL to execute programs, create files,etc. A Shell
Script is a text file that contains a sequence of commands for a UNIX based OS. It is called a
Shell Script because it combines into a "Script" in a single file a sequence of commands, that
would otherwise have to be presented to the system from a keyboard one at a time. A Shell
Script is usually created for command sequences for which a user has a repeated need. You
initiate the sequence of commands in Shell Script by simply entering the name of the Shell
Script on a command line.
Types of Shell Script :-
1. sh - Simple Shell
2. bash - Bourne Again Shell
3. ksh - Korne Shell
4. csh - C Shell
5. ssh - Secure Shell
To use a particular Shell type the Shell name at the command prompt. Eg:- $csh - It will
switch the current Shell to C Shell. To view the current Shell that is being used, type echo $
SHELL at the command prompt.
Code:
#!/bin/bash
#Display current logged in user and logname.
echo "Display current logged in user and logname."
echo "Hi,$USER! This is username."
echo "Hello, $LOGNAME! This is logname"; echo ""
#Display current shell, home directory, operating system type, current path setting
echo "Display current shell, home directory, operating system type, current path setting"
ALL=$(uname -a); echo ""
echo "alternative for -a is: --all: #prints all information";
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
echo "$ALL"
OUTPUT:
co-036@co036-desktop:~$ bash shellbasic.sh
Display current logged in user and logname.
Hi,co-036! This is username.
Hello, co-036! This is logname
Display current shell, home directory, operating system type, current path setting
Experiment No.4
Create a child process in Linux using the fork system call.
Date of Performance:
Date of Submission:
Aim: Create a child process in Linux using the fork system call. From the child process
obtain the process ID of both child and parent by using getpid and getppid system call.
Objective: The purpose of fork() is to create a new process, which becomes the child process
of the caller. After a new child process is created, both processes will execute the next
instruction following the fork() system call.
Theory:
A system call is the programmatic way in which a computer program requests a service from
the kernel of the operating system it is executed on. This may include hardware-related
services (for example, accessing a hard disk drive), creation and execution of new processes,
and communication with integral kernel services such as process scheduling. System calls
provide an essential interface between a process and the operating system.
System call fork() is used to create processes. It takes no arguments and returns a process ID.
The purpose of fork() is to create a new process, which becomes the child process of the
caller.
If fork() returns a negative value, the creation of a child process was unsuccessful.
fork() returns a zero to the newly created child process.
fork() returns a positive value, the process ID of the child process, to the parent. The
returned process ID is of type pid_t defined in sys/types.h. Normally, the process ID is
an integer. Moreover, a process can use function getpid() to retrieve the process ID
assigned to this process.
If the call to fork() is executed successfully, Unix will make two identical copies of address
spaces, one for the parent and the other for the child.
getpid, getppid - get process identification
getpid() returns the process ID (PID) of the calling process. This is often used by routines
that generate unique temporary filenames.
getppid() returns the process ID of the parent of the calling process. This will be either
the ID of the process that created this process using fork().
Code:
#include<stdio.h>
#include <unistd.h>
int main(void)
{
int pid = fork();
if (pid == -1)
{
perror("fork failed");
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
}
else if (pid == 0)
{
printf("Hello from the child process! %d \n", getpid());
}
else
{
printf("Hello from the parent process! %d \n", getppid());
}
}
OUTPUT:
shraddha@shraddha-Inspiron:~$ gcc wikifork.c -o f
shraddha@shraddha-Inspiron:~$ ./f
Hello from the child process! 5907
Hello from the parent process! 5925
shraddha@shraddha-Inspiron:~$ ps
PID TTY TIME CMD
5907 pts/0 00:00:00 bash
5926 pts/0 00:00:00 ps
shraddha@shraddha-Inspiron:~$ ./f
Hello from the child process! 5907
Hello from the parent process! 5930
Experiment No.5
Explore the system calls in Linux.
Date of Performance:
Date of Submission:
Aim: Explore the system calls open, read, write, close, getuid, getgid, getegid, geteuid of
Linux.
Objective: When a program in user mode requires access to RAM or a hardware resource, it
must ask the kernel to provide access to that resource. This is done via a system call.
Theory:
getuid, geteuid - get user identity
getgid, getegid - get group identity
getuid() returns the real user ID of the calling process.
geteuid() returns the e ffective user ID of the calling process.
getgid() returns the real group ID of the calling process.
getegid() returns the effective group ID of the calling process.
All four functions shall always be successful and no return value is reserved to indicate an
error.
Unix-like operating systems identify a user within the kernel by a value called a user
identifier, often abbreviated to user ID or UID. The UID, along with the group
identifier (GID) and other access control criteria, is used to determine which system resources
a user can access.
Effective user ID
The effective UID (euid) of a process is used for most access checks. It is also used as the
owner for files created by that process. The effective GID (egid) of a process also affects
access control and may also affect file creation, depending on the semantics of the specific
kernel implementation in use and possibly the mount options used.
Open: Used to Open the file for reading, writing or both. Open() returns file descriptor
3 because when main process created, then fd 0, 1, 2 are already taken
by stdin, stdout and stderr. So first unused file descriptor is 3 in file descriptor table.
int open(const char *pathname, int flags);
Parameters
Path : path to file which you want to use
use absolute path begin with “/”, when you are not work in same directory of file.
Use relative path which is only file name with extension, when you are work in
same directory of file.
flags : How you like to use
O_RDONLY: read only, O_WRONLY: write only,O_RDWR: read and
write, O_CREAT: create file if it doesn’t exist
Close: Tells the operating system you are done with a file descriptor and Close the file which
pointed by fd.
int close (int fd);
Parameter
fd :file descriptor
Return
0 on success.
-1 on error.
read: Read data from one buffer to file descriptor, Read size bytes from the file specified by
fd into the memory location.
size_t read (int fd, void* buf, size_t cnt);
Parameters
fd: file descripter
buf: buffer to read data from
cnt: length of buffer
Returns: How many bytes were actually read
Write: Write data from file descriptor into buffer, Writes the bytes stored in buf to the file
specified by fd. The file needs to be opened for write operations
size_t write (int fd, void* buf, size_t cnt);
Parameters
fd: file descripter
buf: buffer to write data to
cnt: length of buffer
Returns: How many bytes were actually written
return Number of bytes written on success
return 0 on reaching end of file
return -1 on error
return -1 on signal interrupt
Code:
#include<stdio.h>
#include <unistd.h>
#include<string.h>
#include<fcntl.h>
int main()
{
char data[64];
printf("getuid : %d \n",getuid());
printf("geteuid : %d \n",geteuid());
printf("getgid : %d \n",getgid());
printf("getegid : %d \n",getegid());
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
OUTPUT:
shraddha@shraddha-Inspiron:~$ gcc uid.c -o s
shraddha@shraddha-Inspiron:~$ ./u
getuid : 1000
geteuid : 1000
getgid : 1000
getegid : 1000
fd : 3
0
shraddha@shraddha-Inspiron:~$ ./s
getuid : 1000
geteuid : 1000
getgid : 1000
getegid : 1000
fd : 3
5
shraddha@shraddha-Inspiron:~$ ./s
getuid : 0
geteuid : 0
getgid : 0
getegid : 0
fd : 3
10
Conclusion: Comment on the kernel mode and user mode of the operating system.
Aim: To study and implement process scheduling algorithms FCFS and SJF using CPU-OS
Simulator.
Objective: Its main objective is to increase CPU utilization and hence the throughput of the
system by keeping the CPU as busy as possible.
Theory:
Code:
FCFS
#include<stdio.h>
void main()
{
int g[20],n,bt[10],at[10],i,j;
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
float wt[10],tat[10],awt=0,atat=0;
printf("enter the no. of processes: ");
scanf("%d",&n);
printf("enter arrival time:\n");
for(i=0;i<n;i++)
{
scanf("%d",&at[i]);
}
printf("enter burst time:\n");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
g[0]=0;
for(i=1;i<n+1;i++)
{
g[i]=g[i-1]+bt[i-1];
}
printf("gantt chart\n");
for(i=0;i<n+1;i++)
{
printf("%d\t",g[i]);
}
for(i=0;i<n;i++)
{
awt=awt+g[i]-at[i];
}
for(i=0;i<n;i++)
{
atat=atat+g[i+1]-at[i];
}
awt=awt/n;
atat=atat/n;
printf("\naverage waiting time: %fms\n",awt);
printf("\naverage turn around time: %fms\n",atat);
}
OUTPUT:
SJF
#include<stdio.h>
struct process
{
int pno,at,bt,et,tat,wt;
}p[4],temp;
void main()
{
int i,j;
double avgtat,avgwt,t_tat=0,t_wt=0;
temp=p[j+1];
p[j+1]=p[j];
p[j]=temp;
}
}
}
p[0].wt=0;
p[0].et=0;
for(i=0;i<4;i++)
{
p[i+1].et=p[i].et+p[i].bt;
p[i].wt=p[i].et-p[i].at;
t_wt=t_wt+p[i].wt;
p[i].tat=p[i+1].et-p[i].at;
t_tat=t_tat+p[i].tat;
}
avgtat=t_tat/4;
avgwt=t_wt/4;
printf("\n\nProcess A.T. B.T. C.T. T.A.T. W.T.");
for(i=0;i<4;i++)
{
printf("\nP %d %d %d %d %d %d" ,p[i].pno, p[i].at, p[i].bt, p[i].et, p[i].tat, p[i].wt);
};
printf("\n\nAverage T.A.T. is %lf",avgtat);
printf("\n\nAverage W.T. is %lf\n\n",avgwt);
}
OUTPUT:
Enter arrival time for processes:
P1: 0
P2: 1
P3: 2
P4: 3
Enter burst time for processes:
P1: 5
P2: 3
P3: 8
P4: 6
Process A.T. B.T. C.T. T.A.T. W.T.
P1 0 5 0 5 0
P2 1 3 5 7 4
P4 3 6 8 11 5
P3 2 8 14 20 12
Average T.A.T. is 10.750000
Average W.T. is 5.250000
In the compiler window, enter the following source code in the compiler’s source
editor window (under PROGRAM SOURCE frame title):
PROGRAM LoopTest
i=0
for n = 0 to 40
i=i+1
next
end
Click on the COMPILE button. You should see the code created on the right in
PROGRAM CODE view.
Click on the button SHOW in BINARY CODE view. You should now see the
Hexadecimal Code for LOOPTEST window
Now, this code needs to be loaded in memory so that the CPU can execute it. To do
You should now see the code loaded in memory ready to be executed. You are also
back in the CPU simulator at this stage.
To enter the OS simulator, click on the OS 0 button in the current window. The OS
window opens.
You should see an entry, titled LOOPTEST, in the PROGRAM LIST view. Now
that this program is available to the OS simulator. To create as many instances of
LOOPTEST process click on CREATE NEW PROCESS button as shown below.
Create 4 processes by clicking on the button 4 times. Observe the four instances of the
program being queued in the ready queue which is represented by the READY
PROCESSES view. Make sure the First-Come-First-Served (FCFS) option is selected
in the SCHEDULER/Policies view. At this point the OS is inactive. To activate, first
move the Speed slider to the fastest position, then click on the START button. This
should start the OS simulator running the processes.
Observe the instructions executing in the CPU simulator window. Observe the
processes are running which you can see from two views that are RUNNING
PROCESSES and READY PROCESSES
Now, Figure out the average waiting time using the simulator.
Conclusion: Comment on the CPU-OS simulator used for process scheduling algorithm.
Experiment No.7
Implement deadlock detection and avoidance using Banker’s
algorithm.
Date of Performance:
Date of Submission:
Aim: To study and implement deadlock detection and avoidance using Banker’s algorithm.
Theory:
Data Structures for the Banker’s Algorithm.
Safety Algorithm
Request i = request vector for process Pi . If Requesti [j] = k then process Pi wants k
instances of resource type Rj
1. If Requesti Needi go to step 2. Otherwise, raise error condition, since process has
exceeded its maximum claim
2. If Requesti Available, go to step 3. Otherwise Pi must wait, since resources are
not available 3. Pretend to allocate requested resources to Pi by modifying the state as
follows:
Available = Available – Requesti ;
Allocationi = Allocationi + Requesti ;
Needi = Needi – Requesti ;
1.If safe the resources are allocated to Pi
2. If unsafe Pi must wait, and the old resource-allocation state is restored.
Code:
// Banker's Algorithm
#include <iostream>
using namespace std;
int main()
{
// P0, P1, P2, P3, P4 are the Process names here
int n, m, i, j, k;
n = 5; // Number of processes
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
}
cout << "Following is the SAFE Sequence" << endl;
for (i = 0; i < n - 1; i++)
cout << " P" << ans[i] << " ->";
cout << " P" << ans[n - 1] <<endl;
return (0);
}
Output:
Following is the SAFE Sequence
P1 -> P3 -> P4 -> P0 -> P2
Experiment No.8
CSL704: Computational Lab-I -Operating systems
Implement memory allocation strategy First fit.
Date of Performance:
Date of Submission:
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
Theory:
The primary role of the memory management system is to satisfy requests for memory
allocation. Sometimes this is implicit, as when a new process is created. At other times,
processes explicitly request memory. Either way, the system must locate enough unallocated
memory and assign it to the process.
Partitioning: The simplest methods of allocating memory are based on dividing memory into
areas with fixed partitions.
Selection Policies: If more than one free block can satisfy a request, then which one should
we pick? There are several schemes that are frequently studied and are commonly used.
First Fit: In the first fit approach is to allocate the first free partition or hole large enough
which can accommodate the process. It finishes after finding the first suitable free partition.
Advantage: Fastest algorithm because it searches as little as possible.
Disadvantage: The remaining unused memory areas left after allocation become
waste if it is too smaller. Thus request for larger memory requirement cannot be
accomplished.
Best Fit: The best fit deals with allocating the smallest free partition which meets the
requirement of the requesting process. This algorithm first searches the entire list of free
partitions and considers the smallest hole that is adequate. It then tries to find a hole which is
close to actual process size needed.
Worst fit: In worst fit approach is to locate largest available free portion so that the portion
left will be big enough to be useful. It is the reverse of best fit.
Next Fit: If we want to spread the allocations out more evenly across the memory space, we
often use a policy called next fit. This scheme is very similar to the first fit approach, except
for the place where the search starts.
Code:
#include<stdio.h>
int block[10],process[10],visited[10],pb[10];
void main()
{
int n,m,i,j,frag[10],executed[10];
printf("Enter no. of process\n");
scanf("%d",&n);
printf("Enter no. of blocks\n");
scanf("%d",&m);
printf("Enter the value memory blocks\n");
for(i=0;i<m;i++)
{
scanf("%d",&block[i]);
}
printf("Enter the memory consumed by each process\n");
for(i=0;i<n;i++)
{
scanf("%d",&process[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(process[i]<=block[j]&&visited[j]!=1)
{
frag[j]=block[j]-process[i];
visited[j]=1;
executed[i]=1;
pb[i]=j+1;
break;
}
}
}
for(i=0;i<n;i++)
{
if(executed[i]==1)
printf("p%d is excecuted\n",i+1);
else
printf("p%d is not executed\n",i+1);
}
for(j=0;j<m;j++)
{
if(visited[j]==1)
{
printf("block %d is used\n",(j+1));
printf("Fragmented Memory in block %d is %d\n",j+1,frag[j]);
}
else
printf("block %d is not used\n",j+1);
}
printf("Process \tSize \tBlock \tfragmented Memory\n");
for(i=0;i<n;i++)
{
if(pb[i]<=0)
{
printf("p%d\t %d \tNA \t- \n",i+1,process[i]);
}
else
printf("p%d \t%d \t%d \t%d \n",i+1,process[i],pb[i],frag[pb[i]-1]);
}
}
OUTPUT:
Enter no. of process
4
Enter no. of blocks
5
Enter the value memory blocks
100
500
200
300
600
Enter the memory consumed by each process
212
417
112
426
p1 is excecuted
p2 is excecuted
p3 is excecuted
p4 is not executed
block 1 is not used
block 2 is used
Fragmented Memory in block 2 is 288
block 3 is used
Experiment No.9
Implement page replacement policy LRU.
Date of Performance:
Date of Submission:
Theory:
Demand Paging
A demand paging system is quite similar to a paging system with swapping where processes
reside in secondary memory and pages are loaded only on demand, not in advance. When a
context switch occurs, the operating system does not copy any of the old program’s pages out
to the disk or any of the new program’s pages into the main memory Instead, it just begins
executing the new program after loading the first page and fetches that program’s pages as
they are referenced.
Page Replacement Algorithm
Page replacement algorithms are the techniques using which an Operating System decides
which memory pages to swap out, write to disk when a page of memory needs to be
allocated.
Reference String
The string of memory references is called reference string. Reference strings are generated
artificially or by tracing a given system and recording the address of each memory reference.
Code:
#include<stdio.h>
int input[20]={7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1};
int sol[3]={7,0,1};
int status[3]={0,1,2};
int check()
{
int i;
int min=status[0];
for( i=0;i<3;i++)
{
if(min>status[i])
min=status[i];
}
for(i=0;i<3;i++)
{
if(min==status[i])
return i;
}
}
int present(int n)
{
int i;
for( i=0;i<3;i++)
{
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
if(sol[i]==n)
return 0;
}
return 1;
}
void main()
{
int i,j,m,n;
int hit=0;
int fault=0;
printf("Number of frames is 3 \n");
for(i=0;i<3;i++)
{
printf("%d",sol[i]);
}
printf("\n");
for(j=3;j<=19;j++)
{
for(i=0;i<3;i++)
{
if(present(input[j]))
{
n=check();
sol[n]=input[j];
status[n]=j;
}
.
else
{
hit++;
for(i=0;i<3;i++)
{
if(input[j]==sol[i])
status[i]=j;
}
}
for(i=0;i<3;i++)
{
printf("%d",sol[i]);
}
printf("\n");
}
}
for(i=0;i<3;i++)
printf("%d",sol[i]);
fault=20-hit;
printf("\nNo. of hits - %d \n",hit);
printf("No. of faults - %d",fault);
}
OUTPUT:
Number of frames is 3
701
201
201
203
203
403
402
432
032
032
032
132
132
102
102
107
107
107
107
No. of hits - 8
No. of faults - 12
Experiment No.10
Implement disk scheduling algorithms FCFS, SSTF.
Date of Performance:
Date of Submission:
Objective: The main purpose of disk scheduling algorithm is to select a disk request from the
queue of IO requests and decide the schedule when this request will be processed.
Theory:
TYPES OF DISK SCHEDULING ALGORITHMS
Although there are other algorithms that reduce the seek time of all requests, I will
only concentrate on the following disk scheduling algorithms:
1.First Come-First Serve (FCFS)
2.Shortest Seek Time First (SSTF)
3.Elevator (SCAN)
4.Circular SCAN (C-SCAN)
5.C-LOOK
Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the Read-write head
initially at the track 50 and the tail track being at 199 let us now discuss the different
algorithms.
FCFS
SSTF
Code:
#include<stdio.h>
void main()
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
int a[20],n,i,t=0;
scanf("%d",&a[0]);
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
if(a[i]<a[i+1])
t+=(a[i+1]-a[i]);
else
t+=(a[i]-a[i+1]);
printf("\nProcessing order:");
for(i=0;i<=n;i++)
printf("\t%d",a[i]);
o/p:
ytcem@ytcem-desktop:~$ ./a.out
183
37
122
14
124
65
67
#include<stdio.h>
#include<conio.h>
void main()
int a[20],b[20],d,n,i,j,temp,s,k=0,x=0,t=0;
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
clrscr();
scanf("%d",&a[0]);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
b[k++]=a[0];
for(i=0;i<n;i++)
{
s=1000;
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
d=a[i]-a[j];
else
d=a[j]-a[i];
if(d<s)
{
s=d;
x=j;
}
}
CSL704: Computational Lab-I -Operating systems
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
t+=s;
temp=a[i+1];
a[i+1]=a[x];
a[x]=temp;
b[k++]=a[i+1];
}
printf("\nProcessing order:");
for(i=0;i<=n;i++)
printf("\t%d",b[i]);
o/p:
ytcem@ytcem-desktop:~$ ./a.out