0% found this document useful (0 votes)
13 views64 pages

OS Lab Manual

Uploaded by

ROHIT DADHWAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views64 pages

OS Lab Manual

Uploaded by

ROHIT DADHWAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Department of Information Technology

Lab Manual
Subject: Operating System Lab
Subject Code: BTIT-405-18

B. Tech-IT 2nd Year – 4th Semester

CHANDIGARH ENGINEERING COLLEGE


Landran, Mohali -140307
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

2
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

INDEX
Sr.no Content Page No
I Course Objectives and Outcomes 4
II List of Experiments 5
Installation Process of various operating systems.
1 a. Installation of Microsoft Windows Operating System 6 - 18
b. Installation of Ubuntu Linux Operating System
Implementation of CPU scheduling algorithms to find turnaround
time and waiting time.
a. First Come First Serve (FCFS)
2. 19-27
b. Shortest Job First (SJF)
c. Round Robin
d. Priority
Virtualization, Installation of Virtual Machine Software and
installation of Operating System on Virtual Machine.
3 a. Introduction to Virtualization and Installation of virtual box 28-39
b. Steps to create virtual machine using virtual box
c. Installation of Linux operating systems using virtual box.
Commands for files & directories:
a. cd, ls, cp, md, rm, mkdir, rmdir. Creating and viewing files
4 using cat. 40-49
b. File comparisons, batch commands, kill, ps, who, sleep.
Grep, Cal, Sort,Date commands.
Shell Programming: Basic of shell programming, various types of
shell.
a. Basic of shell programming
5 50-55
b. To study arithmetic expression , conditional statement ,loops
in shell program.
c. Creating shell programs for automating system tasks.
6 Implementation of Bankers algorithm for the purpose of deadlock 56-58
avoidance.
Content Beyond Syllabus
7 Implementation of Reader Writer problem using Semaphores 59-61
8 Implementation of FCFS Disk Scheduling Algorithm 62
9 Implementation of SSTF Disk Scheduling Algorithm 63
Prepared by Approved by
3
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Course Outcomes

Operating Systems Lab (BTIT 405-18) : C216

C216.1 Interpret and implement basic services and functionalities of the operating system
Analyze and simulate CPU Scheduling Algorithms like FCFS, Round Robin, SJF, and
C216.2
Priority
C216.3 Implement commands for files and directories

C216.4 Interpret and implement the concepts of shell programming

C216.5 Simulate file allocation and organization techniques

Course Name: OPREATING SYSTEM LAB (BTIT 405-18)


COURSE PROGRAMME OUTCOMES
OUTCOMES PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
C216.1 2 3 2 3 2 - - - - - - 3 3 2 3
C216.2 2 3 2 3 3 - - - - - - 2 2 2 3
C216.3 3 3 3 3 3 - - - - - - 3 3 2 3
C216.4 3 3 3 3 3 - - - - - - 3 2 2 3
C216.5 3 3 3 3 3 - - - - - - 3 2 2 3
C216 3 3 3 3 3 - - - - - - 3 2 2 3

4
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

List of Experiments
Sr.no List of Experiments Relevance to CO

Installation Process of various operating systems.


1. a. Installation of Microsoft Windows Operating System CO1
b. Installation of Ubuntu Linux Operating System

Implementation of CPU scheduling algorithms to find turnaround time


and waiting time.
a. First Come First Serve (FCFS)
2. CO2
b. Shortest Job First (SJF)
c. Round Robin
d. Priority

Virtualization, Installation of Virtual Machine Software and


installation of Operating System on Virtual Machine.
3. a. Introduction to Virtualization and Installation of virtual box CO1
b. Steps to create virtual machine using virtual box installation of
Linux operating systems using virtual box.
Commands for files & directories:
a. cd, ls, cp, md, rm, mkdir, rmdir. Creating and viewing files
4. using cat. CO3
b. File comparisons batch commands, kill, ps, who, sleep. Grep,
Cal, Sort,Date commands.
Shell Programming: Basic of shell programming, various types of
shell.
a. Basic of shell programming
5. CO4
b. To study arithmetic expression , conditional statement ,loops in
shell program.
c. Creating shell programs for automating system tasks.
Implementation of Bankers algorithm for the purpose of deadlock
6. CO1
avoidance.
7. Implementation of Reader Writer problem using Semaphores CO1
8. Implementation of FCFS Disk Scheduling Algorithm CO5
9. Implementation of SSTF Disk Scheduling Algorithm CO5

PREPARED BY APPROVED BY

5
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

IKGPTU, Jalandhar
Syllabus

6
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:-1(a)

Aim: Installation of Windows operating systems.


Introductions: Windows may be a commissioned OS within which ASCII text file is inaccessible. It is
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.
Steps to install windows Operating System:
1. First get your ISO disk image file from Microsoft.com and buy a CD key.

2. Now get an USB flash drive or optical CD Drive and create a bootable device drive from
PowerISO/Rufus. Here I’m using a USB flash Drive.

6
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

3. Once Completed reboot your PC and press ESC/DEL/F10 to enter into the BIOS. Check the key
online according to your PC brand. In BIOS edit boot sequence program and set your bootable
device on top. Now Save and Exit BIOS. If done correctly your PC will start booting from your
bootable device.

4. Once booted successfully you’ll see the first window of installation. Now here Choose your
Language, Time and currency format, Keyboard layout or let it be the Default i.e. English (US)
and hit Next.

7
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

5. Now you will see a Install Now button hit it to start the setup.

6. Once you hit Install Now the setup will start gathering hardware information and it will
automatically take you to the next level.

8
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

7. Now on next window it will ask you for your CD key. Enter the CD key you have bought from
the Microsoft. You can use the on-screen keyboard or normal keyboard.

8. Now accept the Terms and Conditions from Microsoft and hit Next.

9
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

9. Now choose an option suitable for you. You can upgrade a previously installed window or custom
install from the scratch. Here I’m selecting Custom installation.

10. Now after you select Custom installation you will land on a window called as Partitioning
window. Here you can create different Local Disk partitions of your HDD drive or you can
select the partition containing the previous window.

11. Once you are done with your partitioning hit Next and your window will start installing. After
it finishes up the window will ask for reboot. Reboot the window and remove your bootable
device before window boot again.

10
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

12. Once the window boot again you will see the this personalize section where you can change
the background colour of your window choose your favourite colour and hit Next.

13. Now after Personalizing, select the type of setting you want to set for your window. Here I’m
using Express settings. You can also use custom to change some settings. These setting contains
Automatic Update installation, Data sharing with Microsoft etc.

11
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

14. After your settings you will be asked to Name your PC and User and set a password. You can set
password as None if you want and hit Done. This will be your last step after that your window
will be shown as bellow.

12
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:- 1(b)

Aim: Installation of Linux Operating Systems

Introduction: Ubuntu is an operating system with Linux kernel based on Debian and distributed as free
and open source software. It’s one of the most popular operating systems for Desktop and Server.

Ubuntu can be installed in two ways as follows:

1. Using a DVD?

It’s easy to install Ubuntu from a DVD. Here’s what you need to do:

Put the Ubuntu DVD into the DVD-drive

Restart your computer. You should see a welcome screen prompting you to choose your language and
giving you the option to install Ubuntu or try it from the DVD.

If you don’t get this menu, read the booting from the DVD guide for more information.

2. Using a USB drive

The steps to install Ubuntu using USB are as follows:

Step 1: Most new computers can boot from USB. You should see a welcome screen prompting you to
choose your language and giving you the option to install Ubuntu or try it from the CD.

If your computer doesn’t automatically do so, you might need to press the F12 key to bring up the boot
menu, but be careful not to hold it down – that can cause an error message.

13
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 2: Prepare to install Ubuntu

● We recommend you plug your computer into a power source


● You should also make sure you have enough space on your computer to install Ubuntu
● We advise you to select Download updates while installing and Install this third-party software
now
● You should also stay connected to the internet so you can get the latest updates while you install
Ubuntu
● If you’re not connected to the internet, we’ll help you set up wireless at the next step

Step 3: Set up wireless

If you are not connected to the internet, you will be asked to select a wireless network, if available.
We advise you to connect during the installation so we can ensure your machine is up to date. So, if
you set up your wireless network at this point, it’s worth then clicking the Back button to go back to
the last screen (Preparing to install Ubuntu) and ticking the box marked ’Download updates while
installing’.

14
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 4: Allocate drive space

Use the checkboxes to choose whether you’d like to Install Ubuntu alongside another operating system,
delete your existing operating system and replace it with Ubuntu, or — if you’re an advanced user —
choose the ’Something else’ option

Step 5: Begin the installation

Depending on your previous selections, you can now verify that you have chosen the way in which
you would like to install Ubuntu. The installation process will begin when you click the Install Now
button.Ubuntu needs about 4.5 GB to install, so add a few extra GB to allow for your files.

15
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 6 : Select your location

If you are connected to the internet, this should be done automatically. Check your location is correct
and click ’Forward’ to proceed. If you’re unsure of your time zone, type the name of the town you’re
in or click on the map and we’ll help you find it.

Step 7: Select your preferred keyboard layout

Click on the language option you need. If you’re not sure, click the ’Detect Keyboard Layout’ button
for help.

16
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 8: Enter your login and password details

Step 9: Learn more about Ubuntu while the system installs…

17
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 10: That’s it.

All that’s left is to restart your computer and start enjoying Ubuntu!

Conclusion: Student will understand to install Windows Operating System and Linux Operating
System Successfully.

18
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:- 2(a)

Aim:- Implementation of FCFS scheduling algorithms to find turnaround time and waiting
Time.
Theory:-

FCFS scheduling :-First Come First Serve (FCFS) is an operating system scheduling algorithm that
automatically executes queued requests and processes in order of their arrival. It is the easiest and
simplest CPU scheduling algorithm. In this type of algorithm, processes which requests the CPU first
get the CPU allocation first. This is managed with a FIFO queue. The full form of FCFS is First Come
First Serve.

Algorithm

1. Enter all the processes and their burst time.

2. Find waiting time, WT of all the processes.

3. For the 1st process, WT = 0.

4. For all the next processes i, WT[i] = BT[i-1] + WT[i-1].

5. Calculate Turnaround time = WT + BT for all the processes.

6. Calculate average waiting time = total waiting time/no. of processes.

7. Calculate average turnaround time = total turnaround time/no. of processes.

Example:

19
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Consider the above set of processes that arrive at time zero. The length of the CPU burst time given in
millisecond.

Now we calculate the average waiting time, average turnaround time and throughput.
Average Waiting Time
First of all, we have to calculate the waiting time of each process.
Waiting Time = Starting Time - Arrival Time
Waiting time of

P1 = 0

P2 = 5 - 0 = 5 ms

P3 = 29 - 0 = 29 ms

P4 = 45 - 0 = 45 ms

P5 = 55 - 0 = 55 ms
Average Waiting Time = Waiting Time of all Processes / Total Number of Process
Therefore, average waiting time = (0 + 5 + 29 + 45 + 55) / 5 = 25 ms
Average Turnaround Time
First of all, we have to calculate the turnaround time of each process.
Turnaround Time = Waiting time in the ready queue + executing time + waiting time in waiting-queue
for I/O
Turnaround time of

P1 = 0 + 5 + 0 = 5ms

P2 = 5 + 24 + 0 = 29ms

P3 = 29 + 16 + 0 = 45ms

P4 = 45 + 10 + 0 = 55ms

P5 = 55 + 3 + 0 = 58ms
Average Turnaround Time = (Total Turnaround Time / Total Number of Process)

20
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Total Turnaround Time = (5 + 29 + 45 + 55 + 58)ms = 192ms


Therefore, Average Turnaround Time = (192 / 5)ms = 38.4ms
Throughput
Here, we have a total of five processes. Process P1, P2, P3, P4, and P5 takes 5ms, 24ms, 16ms, 10ms,
and 3ms to execute respectively.
Throughput = (5 + 24 +16 + 10 +3) / 5 = 11.6ms
It means one process executes in every 11.6 ms.

Conclusion: Student will implement First Come First Serve Algorithm and get the desired Result.

21
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:- 2(b)

Aim:-Implementation of SJF scheduling algorithms to find turnaround time and waiting Time.
Theory:-

SJF scheduling:- It is an algorithm in which the process having the smallest execution time is chosen
for the next execution. This scheduling method can be preemptive or non-preemptive. It significantly
reduces the average waiting time for other processes awaiting execution. The full form of SJF is
Shortest Job First.

1 Preemptive:- In Preemptive SJF Scheduling, jobs are put into the ready queue as they come. A
process with shortest burst time begins execution. If a process with even a shorter burst time arrives,
the current process is removed or preempted from execution, and the shorter job is allocated CPU
cycle.

2 Non-Preemptive:- In non-preemptive scheduling, once the CPU cycle is allocated to process, the
process holds it till it reaches a waiting state or terminated.

Algorithm
1. Enter number of processes.

2. Enter the burst time of all the processes.

3. Sort all the processes according to their burst time.

4. Find waiting time, WT of all the processes.

5. For the smallest process, WT = 0.

6. For all the next processes i, find waiting time by adding burst time of all the previously completed
process.

7. Calculate Turnaround time = WT + BT for all the processes.

8. Calculate average waiting time = total waiting time / no. of processes.

9. Calculate average turnaround time= total turnaround time / no. of processes.

22
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Example:

Average Waiting Time

. Here arrival time is common to all processes(i.e., zero).

Waiting Time for


P1 = 3 - 0 = 3ms
P2 = 34 - 0 = 34ms
P3 = 18 - 0 = 18ms
P4 = 8 - 0 = 8ms
P5 = 0ms

Therefore, Average Waiting Time = (3 + 34 + 18 + 8 + 0) / 5 = 12.6ms

Average Turnaround Time

According to the SJF Gantt chart and the turnaround time formulae,

Turnaround Time of
P1 = 3 + 5 = 8ms
P2 = 34 + 24 = 58ms
P3 = 18 + 16 = 34ms
P4 = 8 + 10 = 18ms
P5 = 0 + 3 = 3ms

Therefore, Average Turnaround Time = (8 + 58 + 34 + 18 + 3) / 5 = 24.2ms

Throughput

Here, we have a total of five processes. Process P1, P2, P3, P4, and P5 takes 5ms, 24ms, 16ms,
10ms, and 3ms to execute respectively. Therefore, Throughput will be same as above problem i.e.,
11.6ms for each process.

Conclusion: Student will implement Shortest Job First Algorithm and get the desired Result.

23
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:- 2(c)

Aim:-Implementation of Round Robin scheduling algorithms to find turnaround time and


waiting Time.
Theory:-

Round Robin Scheduling:-

● Round Robin is the preemptive process scheduling algorithm.

● Each process is provided a fix time to execute, it is called a quantum.

● Once a process is executed for a given time period, it is preempted and other process executes
for a given time period.

● Context switching is used to save states of preempted processes.

Algorithim

Step 1: Start the process

Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice

Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time

Step 4: Calculate the no. of time slices for each process where No. of time slice for process (n) = burst

time process (n)/time slice

Step 5: If the burst time is less than the time slice then the no. of time slices =1.

Step 6: Consider the ready queue is a circular Q, calculate a) Waiting time for process (n) = waiting

time of process(n-1)+ burst time of process(n-1 ) + the time difference in getting the CPU

fromprocess(n-1) b) Turnaround time for process(n) = waiting time of process(n) + burst time of

process(n)+ the time difference in getting CPU from process(n).

Step 7: Calculate c) Average waiting time = Total waiting Time / Number of process d) Average

Turnaround time = Total Turnaround Time / Number ofprocess

24
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Quantum=5

Average Waiting Time

For finding Average Waiting Time, we have to find out the waiting time of each process.

Waiting Time of
P1 = 0 + (15 - 5) + (24 - 20) = 14ms
P2 = 5 + (20 - 10) = 15ms
P3 = 10 + (21 - 15) = 16ms

Therefore, Average Waiting Time = (14 + 15 + 16) / 3 = 15ms

Average Turnaround Time

Same concept for finding the Turnaround Time.

Turnaround Time of
P1 = 14 + 30 = 44ms
P2 = 15 + 6 = 21ms
P3 = 16 + 8 = 24ms

Therefore, Average Turnaround Time = (44 + 21 + 24) / 3 = 29.66ms

Throughput

Throughput = (30 + 6 + 8) / 3 = 14.66ms

In 14.66ms, one process executes.

Conclusion: Student will implement Round Robin Algorithm and get the desired Result.

25
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:- 2(d)

Aim:- Implementation of Priority scheduling algorithms to find turnaround time and waiting
Time.
Theory:-

Priority scheduling :-

● Priority scheduling is a non-preemptive algorithm and one of the most common scheduling
algorithms in batch systems.

● Each process is assigned a priority. Process with highest priority is to be executed first and so
on.

● Processes with same priority are executed on first come first served basis.

● Priority can be decided based on memory requirements, time requirements or any other
resource requirement.

Algorithim

Step 1: Start the process

Step 2: Accept the number of processes in the ready Queue

Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time

Step 4: Sort the ready queue according to the priority number.

Step 5: Set the waiting of the first process as ‗0‘ and its burst time as its turnaround time

Step 6: Arrange the processes based on process priority

Step 7: For each process in the Ready Q calculate

Step 8: for each process in the Ready Q calculate a) Waiting time(n)= waiting time (n-1) + Burst
time (n-1) b) Turnaround time (n)= waiting time(n)+Burst time(n)

26
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 9: Calculate c) Average waiting time = Total waiting Time / Number of process d) Average
Turnaround time = Total Turnaround Time / Number of process Print the results in an order.

Step10: Stop

Conclusion: Student will implement Priority Scheduling Algorithm and get the desired Result.

27
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:- 3(a)

Aim: Introduction to Virtualization and Installation of virtual box

Introduction
VirtualBox allows you to run an entire operating system inside another operating system. Please be
aware that you should have a minimum of 512 MB of RAM. 1 GB of RAM or more is recommended.

Advantages of virtual installation

● The size of the installation doesn't have to be predetermined. It can be a dynamically resized
virtual hard drive.
● You do not need to reboot in order to switch between Ubuntu and Windows.
● The virtual machine will use your Windows internet connection, so you don't have to worry
about Ubuntu not detecting your wireless card, if you have one.
● The virtual machine will set up its own video configuration, so you don't have to worry about
installing proprietary graphics drivers to get a reasonable screen resolution.
● You always have Windows to fall back on in case there are any problems. All you have to do
is press the right Control key instead of rebooting your entire computer.
● For troubleshooting purposes, you can easily take screenshots of any part of Ubuntu (including
the boot menu or the login screen).
● It's low commitment. If you later decide you don't like Ubuntu, all you have to do is delete the
virtual hard drive and uninstall VirtualBox.

Disadvantages of virtual installation

● In order to get any kind of decent performance, you need at least 512 MB of RAM, because
you are running an entire operating system (Ubuntu) inside another entire operating system
(Windows). The more memory, the better. I would recommend at least 1 GB of RAM.
● Even though the low commitment factor can seem like an advantage at first, if you later decide
you want to switch to Ubuntu and ditch Windows completely, you cannot simply delete your
Windows partition. You would have to find some way to migrate out your settings from the
virtual machine and then install Ubuntu over Windows outside the virtual machine.
● Every time you want to use Ubuntu, you have to wait for two boot times (the time it takes to
boot Windows, and then the time it takes to boot Ubuntu within Windows).

The installer can be found on its download page here https://www.virtualbox.org/wiki/Downloads


Go to the page above and download the binary version for Windows hosts
After downloading, run the executable to begin installing the software. When you start the installation,
you should get a prompt like the one below.

28
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

During the installation wizard, you’ll get a Network Interfaces warning.. Click Yes to proceed. If
you’re in the process of downloading or copying files and data, this will interrupt your network
connection briefly. So, maybe pause the process or wait until you’re done before installing VirtualBox.

29
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

On the next screen, click Install to begin installing the program.

When prompted with a message to install (Trust) Oracle Universal Serial Bus, click Install to continue.

Continue with the wizard until you’re done.

30
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

After that, VirtualBox should be installed. When you’re done installing, open VirtualBox and install
its extension pack.
The extension pack extends the functionality of VirtualBox base packages. It provides the following
enhancements to VirtualBox:

● Virtual USB 2.0 (EHCI) device


● Virtual USB 3.0 (xHCI) device
● VirtualBox Remote Desktop Protocol (VRDP) support
● Host webcam passthrough
● Intel PXE boot ROM.
● Experimental support for PCI passthrough on Linux hosts
● Disk image encryption with AES algorithm

To install the extension pack, go back to VirtualBox’s download page , download and save the current
pack for all supported platforms’
Step 2: Install VirtualBox extension pack.
After downloading the saving he extension pack. open VirtualBox host software click File –>
Preferences

Then select extension, click the browse button to the right to find the download extension pack. Select
it, agree to the licensing terms and install.

31
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

When you’re done, VirtualBox software will be ready to use and install guest operating systems.

32
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:- 3(b)`

Aim: Steps to create virtual machine using virtual box

Step 1: After you launch VirtualBox from the Windows Start menu, click on New to create a new
virtual machine. When the New Virtual Machine Wizard appears, click Next.

Step 2: You can call the machine whatever you want. If you're installing Ubuntu, it makes sense to
call it Ubuntu, I guess. You should also specify that the operating system is Linux.

33
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 3: VirtualBox will try to guess how much of your memory (or RAM) to allocate for the virtual
machine. If you have 1 GB or less of RAM, I would advise you stick with the recommendation. If,
however, you have over 1 GB, about a quarter your RAM or less should be fine. For example, if you
have 2 GB of RAM, 512 MB is fine to allocate. If you have 4 GB of RAM, 1 GB is fine to allocate. If
you have no idea what RAM is or how much of it you have, just go with the default.

Click Next.

Step 4: If this is your first time using VirtualBox (which it probably is if you need a tutorial on how to
use it), then you do want to Create new hard disk and then click Next.

34
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 5: Click Next again.

Step 6: Theoretically, a dynamically expanding virtual hard drive is best, because it'll take up only
what you actually use. I have come upon weird situations, though, when installing new software in a
virtualized Ubuntu, in which the virtual hard drive just fills up instead of expanding. So I would
actually recommend picking a Fixed-size storage.

Step 7: Ubuntu's default installation is less than 3 GB. If you plan on adding software or downloading
large files in your virtualized Ubuntu, you should tack on some buffer.

35
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 8: Click Create and wait for the virtual hard drive to be created. This is actually just a very large
file that lives inside of your Windows installation.

36
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment no. 3(c)


Aim: Installation of Linux operating systems using virtual box.

Step 1: The next thing to do to make the (currently blank) virtual hard drive useful is to add the
downloaded Ubuntu disk image (the .iso) boot on your virtual machine. Click on Settings and Storage.
Then, under CD/DVD Device, next to Empty, you'll see a little folder icon. Click that.

Step 2:Select the Ubuntu .iso you downloaded earlier.

37
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 3: Once you've selected it, click OK.

Then double-click your virtual machine to start it up.

Step 4: You may get a bunch of random warnings/instructions about how to operate the guest operating
system within VirtualBox. Read those, and then you may also want to mark not to see those again.

38
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Step 5: Wait for Ubuntu to boot up.

Step 6: Once it's started up, just follow the regular installation procedure as if you were installing.

Conclusion: Student will install Virtual Box and implement virtualization at the end of Experiment.

39
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No. :- 4(a)

Aim:- LINUX, file system, creating, copying, removing, renaming, and moving files in LINUX
operating system.

Objective:-

● To study Linux file system.


● To study commands for creating files : TOUCH and CAT
● To study commands for copying file in Linux : CP
● To study command for removing ,renaming and moving file : RM ,MV
● To study Linux file system.

Theory:-

FILE SYSTEM:- It is used to control how data is stored and retrieved. Without a file system,
information placed in a storage area would be one large body of data with no way to tell where one
piece of information stops and the next begins.

There are many different kinds of file systems. Each one has different structure and logic,
properties of speed, flexibility, security, size and more. Some file systems have been designed to be
used for specific applications. For example, the ISO 9660 file system is designed specifically for
optical discs.

File systems can be used on many different kinds of storage devices. Each storage device uses a
different kind of media. The most common storage device in use today is a hard drive whose media is
a disc that has been coated with a magnetic film. In some cases, the computer's main memory (RAM)
is used to create a temporary file system for short term use

TYPES OF FILE SYSTEM :-

File system types can be classified into disk/tape file systems, network file systems and special-purpose
file systems.

40
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

1. Disk file systems:-A disk file system takes advantages of the ability of disk storage media to
randomly address data in a short amount of time. This permits multiple users access to various data on
the disk without regard to the sequential location of the data. Examples include FAT, exFAT, NTFS,
HFS and

2. Flash file systems:- A flash file system considers the special abilities, performance and restrictions
of flash memory devices. Frequently a disk file system can use a flash memory device as the underlying
storage media but it is much better to use a file system specifically designed for a flash device.

3. Tape file systems:- A tape file system is a file system and tape format designed to store files on tape
in a self-describing form. Magnetic tapes are sequential storage media with significantly longer
random data access times than disks, posing challenges to the creation and efficient management of a
general-purpose file system.

4. Database file systems:- Another concept for file management is the idea of a database-based file
system. Instead of, or in addition to, hierarchical structured management, files are identified by their
characteristics, like type of file, topic, author, or similar. Very large file systems, embodied by
applications like Apache Hoodoo and Google File System, use some database file system concepts.

5. Transactional file systems:-Transaction processing introduces the isolation guarantee, which states
that operations within a transaction are hidden from other threads on the system until the transaction
commits, and that interfering operations on the system will be properly serialized with the transaction..
This means that if there is a crash or power failure, after recovery, the stored state will be consistent.

6. Network file systems:- A network file system is a file system that acts as a client for a remote file
access protocol, providing access to files on a server. Examples of network file systems include clients
for the NFS, AFS, SMB protocols, and file-system-like clients for FTP and WebDAV.

7. Shared disk file systems:- A shared disk file system is one in which a number of machines (usually
servers) all have access to the same external disk subsystem (usually a SAN). The file system arbitrates
access to that subsystem, preventing write collisions. Examples include GFS2 from Red Hat, GPFS
from IBM, SFS from Dataflow, CXFS from SGI and StorNext from Quantum Corporation.

41
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

EXAMPLES FOR DIFFERENT FILE SYSTEM:-

(1) FAT:- File Allocation Table FAT is supported by almost all operating systems for personal
computers, including all versions of Windows and MS-DOS/PC DOS and DR-DOS. SCP86-
DOSDigital Research Concurrent DOSCP/M-86The FAT file systems are therefore well-suited as
a universal exchange format between computers and devices of most any type and age. Over the
years, the file system has been expanded from FAT12 to FAT16 and FAT32. Various features have
been added to the file system including subdirectories, codepage support, extended attributes, and
long filenames.

The FAT12 and FAT16 file systems had a limit on the number of entries in the root directory of
the file system and had restrictions on the maximum size of FAT-formatted disks or partitions.FAT32
addresses the limitations in FAT12 and FAT16, except for the file size limit of close to 4 GB, but it
remains limited compared to NTFS.

(2) NTFS:- NTFS, introduced with the Windows NT operating system in 1993, allowed ACL-based
permission control. Other features also supported by NTFS include hard links, multiple file
streams, attribute indexing, quota tracking, sparse files, encryption, compression, and reparse
points (directories working as mount-points for other file systems, symlinks, junctions, remote
storage links
(3) exFAT:- exFAT is a proprietary and patent-protected file system with certain advantages over
NTFS with regard to file system overhead.exFAT is not backward compatible with FAT file
systems such as FAT12, FAT16 or FAT32. The file system is supported with newer Windows
systems, such as Windows Server 2003, Windows Vista, Windows 2008, Windows 7, Windows
8, and more recently, support has been added for Windows XP.[20]exFAT is supported in Mac OS
X starting with version.
● To study commands for creating files : TOUCH and CAT
(1) Touch :-The touch command allows users to make files using the Linux CLI. Just as the
mkdir command makes directories, the touch command makes files. Just as you would
make a .doc or a .txt using a PC desktop, the touch command makes empty files.
Syntax: - touch file name
Touch file 1 file 2 …….n

42
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

An example of the touch command: touch testfile.txt


The example touch command effectively created the file testfile.txt. As noted by the
extension, the file created is a .txt or text file. To equate, a .txt file in Linux is akin to a .txt
notebook file within a Windows or Mac OS.
Example:- touch a1 a2 a3 .
It means we can also create multiple files using this command.A here we created 3 different
files a1,a2 and a3.

(2) CAT:-This command is used to display the contents of a file. You can read the content of a file
using cat command. Because by using command touch can can’t be able to write on a file you
can only able to create a new empty file .That’s why by using cat command we can write on
our new file.
Syntax for this command:- cat > file name
Example:- $ cat > a4
This mean we are writing something in file a4 then we save the content by using ctrl d .
If we want to see the content of file a4 then we write command $cat a4 .
We can also copy multiple files .
Example:- cat a4 a5 > b1
This mean we are copying contents of both file a4 and a5 into file b1.
● To study commands for copying file in Linux : CP

(1)Cp command:-This command is used to copy file and directory. Whenever we want to copy
content of one file to another then we use this command. The cp command makes a copy of a
file for you.

For example:- cp file footmarks an exact copy of the file whose name you entered and name
the copy too, but the first file will still exist with its original name. After you use mv, the
original file no longer exists, but after you use cp, that file stays and a new copy is made.

cp [option(s)] sourcefile targetfile:- Copies sourcefile to targetfile.

Syntax of command is:-

43
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Cp file 1 file 2

Cp file 1 file 2 file 3

Example:- cp a4 a5
This command means we are copying content of file a4 to file a5.
● To study command for Removing ,Renaming and Moving file : RM ,MV
(1) MOVING COMMAND :- MV
The MV command - move - allows a user to move a file to another folder or directory. MV
command can be used to move any number of files and folders in a single command.
The syntax is as follows:-

mv source target
mv folder1 folder2 target
mv folder1 file1 target
mv -option source target

An example of the mv command is:-


mv [option(s)] source file target file
Copies source file to target file then deletes the original source file..

(2) RENAMING COMMAND :-In order to rename a file in Linux you can use either of two
approaches

(A) Create a copy of the existing file with the new desired name and then delete the old Rename
with copy and delete.

EXAMPLE:- $ cp oldfile newfile.

This creates a copy of the same file with a new name in the same location.

$ rm oldfile

44
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

This will delete the old file keeping the newfile intact file.

(B) Rename the file by moving it with the mv command.

EXAMPLE:-

Rename by moving

$mv old-file-name new-file-name

This just moves the old file, to a new name. rm [option(s)] file(s)

Removes the specified files from the file system. Directories are not removed by rm unless the
option -r is used.

-r Deletes any existing subdirectories . -I Waits for confirmation before deleting each file

(C) Renaming a directory:-

Renaming a directory in Linux and Unix is similar to renaming a file. All we need to do is replace the
file name with the directory name that is to be renamed.

For example, if we wanted to rename the directory “RR1″ to “ST1″, then we can use the following
command.

$ mv RR1 ST1

(3) REMOVING COMMAND: RM


The rm command - remove - like the rmdir command is meant to remove files from your
Linux OS. Whereas the rmdir command will remove directories and files held within, the
rm command will delete created files. An example of the rm command:

rm testfile.txt
The aforementioned command removed testfile.txt. Interestingly, whereas the rmdir
command will only delete an empty directory, the rm command will remove both files and
45
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

directories with files in it. This said, the rm command carries more weight than the rmdir
command and should be used with more specificity.

Remove a directory :-rmdir


The rmdir - remove directory - command allows the user to remove an existing command
using the Linux CLI. An example of the rmdir command:
rmdir testdirectory
The example command removed the directory "testdirectory".
It should be noted: both the mkdir and rmdir commands make and remove directories. They
do not make files and they will also not remove a directory which has files in it. The mkdir
will make an empty directory and the rmdir command will remove an empty directory.

● To study the commands for listing files and directory: ls , ls-a , ls-l , ls using wild cards.
Basically ls means listing files .so files can be hidden , it can be long listing ,or it can be existing
files so that’s why ls command can be used in many ways i.e.

1. Ls
2. Ls – a
3. Ls – l
4. Ls - a – l
5. Ls using wild cards

1. LS COMMAND: - This command is used for showing exixting all files and directory
,when ever we want to see saved files and directory we always use ls command
for it .it shows file with different colors like blue color shows directories and
while colour shows files .
2. LS – A COMMAND:- This command is used to listing out all hidden files. That’s why
for viewing hidden files we use ls- a command.sometime we hide our file for preveting
its viewing that’s why to see hidden files we use this command.

46
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

3. LS- L COMMAND :- This command is used for viewing long listing files , it means it
shows a long list of many no of files .
4. LS – A - L COMMAND :- This command is used to show both hidden files and long
listing files.
5. LS COMMAND USING WILD CARDS :- ls command can be used with wild cards in
following ways
● Ls a*:- this command list out all files which are saved by name starting with a letter . we can
also use another alphabet using same command inspite of writing any alphabet at place of a.
● Ls a ? : - This command is used to list out those files whose first letter are saved with alphabet
a and that file consist of only two alphabets ..
● Ls a??:- this another command of ls using wild cards that shows file whose first letter is starting
with a and file contains three alphabets .
● To study commands for changing permission of files:chmod

Permissions are of three types:-


1. Owner of file:- this tells about the owner of given file.
2. Group:- its that group to which owner belons to .
3. Other:- this includes those files which donot belongs to owner file and group .
Permission includes :-
● Read a file
● Write a file
● Execute a file .

● To study commands for changing directory,creating directory,removing directory and to see


present working directory: mkdir , rmdir ,cd , pwd .

1. MKDIR COMMAND: - This command is used to make directory .mk stand for make
and dir stand for directory.
2. RMDIR COMMAND:- This command is used to remove directory. whenever we have
no of saved directory are existing and when we want to remove one of them then we

47
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

us this command along with rmdir we write the name of directory to whom we want to
remove .

Conclusion: Student will execute various commands and get the desired results.

48
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No:- 4(b)

Aim:- To work on miscellaneous commands in Linux. (Logname, Who, who am I, date, cal, wc,
sort, grep).

OBJECTIVE:- To study commands :logname ,who ,who am I ,date , time , cal , wc , sort , grep .

(1) LOGNAME COMMAND:- This command tells the user name on which we are working .

(2) WHO COMMAND:- This display all user name that are working on our computer.

(3) WHO AM I COMMAND :- This command used to display name of current user.

(4) DATE COMMAND:- this commands tell current user details only .

(5) CAL COMMAND:- This command will display date only .

(6) WC COMMANMD:- WC means word count . Thisa command counts the no of lines and no
of characters .

(7) SORT COMMAND:- This is very important command .this command is used to sort inside
file details accordingly.

(8) GREP COMMAND:- This command is also very important command .GREP means globally
search a regular expression and print it .By using this command we can search single letter in
file and also can search through line content in a file .

Conclusion: Student will execute miscellaneous commands and get the information about
word count ,sort and who is login into the system.

49
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No.. :- 5(a)

Aim:- To study shell programming in linux.

OBJECTIVES:-

⮚ To use ECHO command


⮚ To use read command
⮚ To solve arithmetic expression

SHELL:-Shell provide a environment where users can runs its commands ,programs ,and shell script.

SHELL SCRIPT:-shell script is a computer program designed to be run by the Unix shell, a command
line interpreter.[1] The various dialects of shell scripts are considered to be scripting languages.

Typical operations performed by shell scripts include file manipulation, program execution, and
printing text.

Advantages and disadvantages:-

● Perhaps the biggest advantage of writing a shell script is that the commands and syntax are
exactly the same as those directly entered at the command line.
● On the other hand, shell scripting is prone to costly errors.
● Another significant disadvantage is the slow execution speed and the need to launch a new
process for almost every shell command executed.

⮚ To use ECHO command

ECHO:- this command is used when we want to display the content as it is written .this comman
dwill display sentence or word as is.

SYNTAX:- echo “ …………”


⮚ To use read command
READ COMMAND:- this command is used when user want to enter different values to the
different types . so by using this command we can insert values to data.

50
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

SYNTAX:- read data1 data2 data3


⮚ To solve arithmetic expression

ARITHMATIC COMMANDS:- these are command for solving arithmetic expressions like
addition (+) ,subtraction(-),multiplication(\*) etc.for solving arithmetic expresiion we need
command like EXPR .

SYNTAX:- val=expr $value1 + $value2


$echo “…….”

Outcome: Students will learn the creation of script, various arithmetic expressions and read values
from the script.

51
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No. :-5(b)


Aim:- To study arithmetic expression , conditional statement ,loops in shell program.

OBJECTIVE:-

● To perform arithmetic operation using expr.


● To execute conditional statement
✔ If………..then……….fi
✔ If………..then….. ..else……..fi
● To execute loops in shell using relational operator
✔ While …….do…….done

● To perform arithmetic operation using expr.


ARITHMATIC OPERATION:- Arithmatic operations are like + ,- ,/ ,* ,% etc .we can also
perform arithmetic operation in linux using shell programming. For solving these operation we
need command named EXPR .

● To execute conditional statement

CONDITIONAL STATEMENT:- conditional statements are those whose outcome depends


upon some condition i.e. either they are true or false .basdicaly these statements are if , else , else if
etc.nested of these statements are true.

✔ EXAMPLE:- If………..then……….fi

✔ If………..then….. ..else……..fi

● To execute loops in shell using relational operator


While …….do…….done:- While do then can also be implemented using relational operator
.relational operators are like

❖ Equal to--- ( -eq)

52
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

❖ Not equal to---(-ne)


❖ Greater then---(gt)
❖ Greater then equal to---(-ge)
❖ Less then equal to---(-le)

Conclusion: Students will learn the various statements and loops and implement program using these
statements.

53
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No.:- 5(c)

Aim: Creating shell programs for automating system tasks.

To add two Numbers

ALGORITHM:

• Using expr command with quotes sum=`expr $num1 + $num2`

• Use expr command inclosed with brackets and start with dollar symbol. sum=$ (expr $num1 +

$num2)

• This is my preferred way to directly with the shell. sum=$ ( ($num1 + $num2))

To write a shell program to check whether the given number is prime or not.

ALGORITHM:

· Get the given string.

· Separate the digits using the formula q=`expr $n % 10`.

· Calculate sum of cube of digits by the formula a=`expr $a + $r /* $r /* $r`.

· Compute the and display result .

To find greatest of three numbers

1. Get three numbers. Say num1, num2, num2


2. If (num1 > num2) and (num1 > num3)
echo value of num1
3. elif(num2 > num1) and (num2 > num3)
echo value of num2
4. Otherwise,
echo value of num3
To add array elements

54
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

1. Declare and initialize the array elements

2. Iterate the array using for loop

3. Add each array element

4. Print the result

Write a Shell program to find the factorial of a number

SEPT 1: Start the program.

STEP 2: Read the value of n.

STEP 3: Calculate „i=expr $n-1‟.

STEP 4: If the value of i is greater than 1 then calculate „n=expr $n \* $i‟ and „i=expr $i – 1‟

STEP 5: Print the factorial of the given number.

Conclusion: Student will implement different shell programs and get the desired results.

55
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No. :-6


Aim: To write a C program to implement banker‟s algorithm for deadlock avoidance.

ALGORITHM:

Step-1: Start the program.

Step-2: Declare the memory for the process.

Step-3: Read the number of process, resources, allocation matrix and available matrix.

Step-4: Compare each and every process using the banker‟s algorithm.

Step-5: If the process is in safe state then it is a not a deadlock process otherwise it is a

deadlock process

Step-6: produce the result of state of process

Step-7: Stop the program

Working:

1. There are two vectors Wok and Finish of length m and n in a safety algorithm.

Initialize: Work = Available

Finish[i] = false; for I = 0, 1, 2, 3, 4… n - 1.

2. Check the availability status for each type of resources [i], such as:

Need[i] <= Work

Finish[i] == false

If the i does not exist, go to step 4.

3. Work = Work +Allocation(i) // to get new resource allocation

56
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Finish[i] = true

Go to step 2 to check the status of resource availability for the next process.

4. If Finish[i] == true; it means that the system is safe for all processes.

Resource Request Algorithm

A resource request algorithm checks how a system will behave when a process makes each type of
resource request in a system as a request matrix.

Let create a resource request array R[i] for each process P[i]. If the Resource Requesti [j] equal to 'K',
which means the process P[i] requires 'k' instances of Resources type R[j] in the system.

1. When the number of requested resources of each type is less than the Need resources, go to step 2
and if the condition fails, which means that the process P[i] exceeds its maximum claim for the
resource. As the expression suggests:

If Request(i) <= Need

Go to step 2;

2. And when the number of requested resources of each type is less than the available resource for
each process, go to step (3). As the expression suggests:

If Request(i) <= Available

Else Process P[i] must wait for the resource since it is not available for use.

3. When the requested resource is allocated to the process by changing state:

Available = Available - Request

Allocation(i) = Allocation(i) + Request (i)

Needi = Needi – Requesti

57
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

When the resource allocation state is safe, its resources are allocated to the process P(i). And if the ew
state is unsafe, the Process P (i) has to wait for each type of Request R(i) and restore the old resource-
allocation state.

Conclusion: Students will learn the Bankers Algorithm and implement the same to get desired results.

58
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No.:- 7
Aim: Implementation of Reader-writer problem using Semaphores

• If one of the person tries editing the file, no other person should be reading or writing at the
same time, otherwise changes will not be visible to him/her.
• However if some person is reading the file, then others may read it at the same time.

readers-writers problem
Problem parameters:

• One set of data is shared among a number of processes


• Once a writer is ready, it performs its write. Only one writer may write at a time
• If a process is writing, no other process can read it
• If at least one reader is reading, no other process can write
• Readers may not write and only read

when Reader has the Priority over Writer


There are four Types of cases could happen here.

Case Process 1 Process 2 Allowed/Not Allowed

Case 1 Writing Writing Not Allowed

Case 2 Writing Reading Not Allowed

Case 3 Reading Writing Not Allowed

Case 4 Reading Reading Allowed

Here priority means, no reader should wait if the share is currently opened for reading.

Three variables are used: mutex, wrt, readcnt to implement solution

1. semaphore mutex, wrt; // semaphore mutex is used to ensure mutual exclusion


when readcnt is updated i.e. when any reader enters or exit from the critical section and
semaphore wrt is used by both readers and writers
2. int readcnt; // readcnt tells the number of processes performing read in the critical
section, initially 0

59
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Functions for semaphore :


– wait() : decrements the semaphore value.

– signal() : increments the semaphore value.

Writer process:

1. Writer requests the entry to critical section.


2. If allowed i.e. wait() gives a true value, it enters and performs the write. If not allowed, it
keeps on waiting.
3. It exits the critical section.

do {

// writer requests for critical section

wait(wrt);

// performs the write

// leaves the critical section

signal(wrt);

} while(true);

Reader process:

1. Reader requests the entry to critical section.


2. If allowed:
• it increments the count of number of readers inside the critical section. If this reader is
the first reader entering, it locks the wrt semaphore to restrict the entry of writers if
any reader is inside.
• It then, signals mutex as any other reader is allowed to enter while others are already
reading.
• After performing reading, it exits the critical section. When exiting, it checks if no
more reader is inside, it signals the semaphore “wrt” as now, writer can enter the
critical section.
3. If not allowed, it keeps on waiting.

60
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

do {

// Reader wants to enter the critical section

wait(mutex);

// The number of readers has now increased by 1

readcnt++;

// there is atleast one reader in the critical section

// this ensure no writer can enter if there is even one reader


// thus we give preference to readers here
if (readcnt==1)
wait(wrt);

// other readers can enter while this current reader is inside


// the critical section
signal(mutex);

// current reader performs reading here


wait(mutex); // a reader wants to leave

readcnt--;

// that is, no reader is left in the critical section,


if (readcnt == 0)
signal(wrt); // writers can enter

signal(mutex); // reader leaves

} while(true);
Thus, the semaphore ‘wrt‘ is queued on both readers and writers in a manner such that
preference is given to readers if writers are also there. Thus, no reader is waiting simply because
a writer has requested to enter the critical section.

Conclusion: Students will learn the Reader Writer Problem implement the same and get desired
results.

61
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No.:- 8
Aim: Implementation of FCFS Disk Scheduling Algorithm.

First Come First Serve (FCFS)


FCFS is the simple. As the name suggests, this algorithm entertains requests in the order they
arrive in the disk queue. The algorithm looks very fair and there is no starvation (all requests are
serviced sequentially) but generally, it does not provide the fastest service.
Algorithm:
1. Let Request array represents an array storing indexes of tracks that have been requested in
ascending order of their time of arrival. ‘head’ is the position of disk head.
2. Let us one by one take the tracks in default order and calculate the absolute distance of the
track from the head.
3. Increment the total seek count with this distance.
4. Currently serviced track position now becomes the new head position.
5. Go to step 2 until all tracks in request array have not been serviced.
Example:
Input:
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50
Output:
Total number of seek operations = 510
Seek Sequence is
176
79
34
60
92
11
41
114
The following chart shows the sequence in which requested tracks are serviced using FCFS.

Therefore, the total seek count is calculated as:

= (176-50)+(176-79)+(79-34)+(60-34)+(92-60)+(92-11)+(41-11)+(114-41)

= 510

Conclusion: Students will learn FCFS Disk Algorithm and implement the same to get desired results.

62
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab

Experiment No.:--9
Aim: Implementation of SSTF Disk Scheduling Algorithm

Shortest Seek Time First (SSTF) –


Basic idea is the tracks which are closer to current disk head position should be serviced first in
order to minimise the seek operations.
Advantages of Shortest Seek Time First (SSTF) –
1. Better performance than FCFS scheduling algorithm.
2. It provides better throughput.
3. This algorithm is used in Batch Processing system where throughput is more important.
4. It has less average response and waiting time.
Disadvantages of Shortest Seek Time First (SSTF) –
1. Starvation is possible for some requests as it favours easy to reach request and ignores the
far away processes.
2. There is lack of predictability because of high variance of response time.
3. Switching direction slows things down.
Algorithm –
1. Let Request array represents an array storing indexes of tracks that have been requested.
‘head’ is the position of disk head.
2. Find the positive distance of all tracks in the request array from head.
3. Find a track from requested array which has not been accessed/serviced yet and has
minimum distance from head.
4. Increment the total seek count with this distance.
5. Currently serviced track position now becomes the new head position.
6. Go to step 2 until all tracks in request array have not been serviced.

Example –
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50
The following chart shows the sequence in which requested tracks are serviced using SSTF.
Therefore, total seek count is calculated as:

= (50-41)+(41-34)+(34-11)+(60-11)+(79-60)+(92-79)+(114-92)+(176-114)

= 204

Which can also be directly calculated as: (50-11)+(176-11)

Conclusion: Students will learn Shortest Seek Time First Algorithm and find out the Seek Time and
get the desired results.

63

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy