0% found this document useful (0 votes)
12 views

Computer Ass 2

Uploaded by

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

Computer Ass 2

Uploaded by

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

Questions # 1.

Explain working of Central Processing Unit (CPU) in detail .

DEFINITION
A central processing unit (CPU), also called a central processor or main processor, is the electronic
circuitry within a computer that executes instructions

that make up a computer program. The CPU performs basic arithmetic, logic, controlling, and
input/output (I/O) operations specified by the instructions in the program. The computer industry
used the term "central processing unit" as early as 1955.Traditionally, the term "CPU" refers to a
processor, more specifically to its processing unit and control unit (CU), distinguishing these core el-
ements of a computer from external components such as main memor.

WORKING OF CPU
Most things in a computer are relatively simple to understand: the RAM, the storage, the peripherals,
and the software all work together to make a computer function. But the heart of your system, the
CPU, seems like magic even to many tech people. Here, we’ll do our best to break it down.

Most of the research for this article comes from “But How Do It Know?” by J. Clark Scott. It’s a fan-
tastic read, goes into much more depth than this article will, and is well worth the couple bucks on
Amazon.

One note before we begin: modern CPUs are orders of magnitude more complex than what we’re
outlining here. It’s nearly impossible for one person to understand every nuance of a chip with over a
billion transistors. However, the basic principles of how it all fits together remain the same, and un-
derstanding the basics will give you a better understanding of modern systems.

Starting Small

Computers operate in binary. They only understand two states: on and off. To perform calculations
in binary, they use what’s called a transistor. The transistor only allows the source current to flow
through it to the drain if there is current across the gate. Essentially, this forms a binary switch,
which cuts the wire off depending on a second input signal.Modern computers use billions of transis-
tors to perform calculations, but at the lowest levels, you only need a handful to form the most basic
components, known as gates.

Logic Gates

Stack a few transistors properly, and you have what’s known as a logic gate. Logic gates take two bi-
nary inputs, perform an operation on them, and return an output. The OR gate, for example, returns
true if either of the inputs is true. The AND gate checks if both inputs are true, XOR checks if only
one of the inputs are true, and the N-variants (NOR, NAND, and XNOR) are inverted versions of
their base gates.

Doing Math With Gates


With just two gates you can do basic binary addition. This diagram above shows a half adder, created
using Logicly, a free online playground for logic gates. The XOR gate here will turn on if just one of
the inputs is on, but not both. The AND gate will turn on if both inputs are on, but stay off if there’s
no input. So if both are on, the XOR stays off, and the AND gate turns on, coming to the correct an-
swer of two:

This gives us a simple setup with three distinct outputs: zero, one, and two. But one bit can’t store
anything higher than 1, and this machine isn’t too useful as it only solves one of the simplest math
problems possible. But this is only a half adder, and if you connect two of them with another input,
you get a full adder:
The full adder has three inputs—the two numbers to add, and a “carry.” The carry is used when the
final number exceeds what can be stored in a single bit. Full adders will be linked in a chain, and the
carry is passed from one adder to the next. The carry is added to the result of the XOR gate in the
first half adder, and there’s an extra OR gate to handle both cases when the so that would need to be
on.

When both inputs are on, the carry turns on, and sends it to the next full adder in the chain:

And this is about as complex as addition gets. Moving up to more bits essentially just means more
full adders in a longer chain.

Most other math operations can be done with addition; multiplication is just repeated addition, sub-
traction can be done with some fancy bit inversion, and division is just repeated subtraction. And
while all modern computers have hardware-based solutions to speed up more complicated opera-
tions, you can technically do it all with the full adder.

The Bus, and Memory


Right now, our computer is nothing more than a bad calculator. This is because it can’t remember
anything, and does nothing with its outputs. Shown above is a memory cell, which can do all of that.
Under the hood, it uses a lot of NAND gates, and in real life can be quite different depending on the
storage technique, but its function is the same. You give it some inputs, turn on the ‘write’ bit, and it
will store the inputs inside the cell. This isn’t just a memory cell, as we also need a way to read infor-
mation from it. This is done with an enabler, which is a collection of AND gates for each bit in the
memory, all tied to another input, the “read” bit. The write and read bits are often called “set” and
“enable” as well.

This whole package is wrapped up into what’s known as a register. These registers are connected to
the bus, which is a bundle of wires running around the whole system, connected to every component.
Even modern computers have a bus, though they may have multiple buses to improve multitasking
performance.
Each register still has a write and read bit, but in this setup, the input and output are the same thing.
This is actually good. For example. If you wanted to copy the contents of R1 into R2, you would turn
on the read bit for R1, which would push the contents of R1 onto the bus. While the read bit is on,
you’d turn on the write bit for R2, which would copy the bus contents into R2.

Registers are used to make RAM as well. RAM is often laid out in a grid, with wires going in two di-
rections:

The decoders take a binary input and turn on the corresponding numbered wire. For example, “11” is
3 in binary, the highest 2-bit number, so the decoder would turn on the highest wire. At each inter-
section, there’s a register. All of these are connected to the central bus, and to a central write and
read input. Both the read and the write input will only turn on if the two wires crossing over the reg-
ister are also on, effectively allowing you to select the register from which to write and read. Again,
modern RAM is far more complicated, but this setup still works.

The Clock, the Stepper, and the Decoder


Registers are used everywhere and are the basic tool for moving data around and storing information
in the CPU. So what tells them to move things around?

The clock is the first component in the core of the CPU and will turn off and on at a set interval,
measured in hertz, or cycles per second. This is the speed you see advertised alongside CPUs; a 5
GHz chip can perform 5 billion cycles per second. Clock speed is often a very good metric for how
fast a CPU is.
The clock has three different states: the base clock, the enable clock, and the set clock. The base
clock will be on for half a cycle, and off for the other half. The enable clock is used to turn on regis-
ters and will need to be on for longer to make sure that the data is enabled. The set clock always
needs to be on at the same time as the enable clock, or else incorrect data could be written.

The clock is connected to the stepper, which will count from one to the max step, and reset itself
back to one when it’s done. The clock is also connected to AND gates for each register that the CPU
can write to:

These AND gates are also connected to the output of another component, the instruction decoder.
The instruction decoder takes an instruction like “SET R2 TO R1” and decodes it into something that
the CPU can understand. It has its own internal register, called the “Instruction Register,” which is
where the current operation is stored. How exactly it does this comes down to the system you’re run-
ning on, but once it’s decoded, it will turn on the correct set and enable bits for the correct registers,
which will fire off in accordance to the clock.

Program instructions are stored in RAM (or L1 cache on modern systems, closer to the CPU). Since
program data is stored in registers, just like every other variable, it can be manipulated on the fly to
jump around the program. This is how programs get their structure, with loops and if statements. A
jump instruction sets the current location in memory that the instruction decoder is reading from to a
different location.

How It All Comes Together

Now, our gross oversimplification of how a CPU works is complete. The main bus spans the whole
system and connects to all of the registers. The full adders, along with a bunch of other operations,
are packed into the Arithmetic Logic Unit, or the ALU. This ALU will have connections to the bus,
and will also have its own registers for storing the second number it’s operating on.

To perform a calculation, program data is loaded from system RAM into the control section. The
control section reads two numbers from RAM, loads the first one into the ALU’s instruction register,
and then loads the second one onto the bus. Meanwhile, it sends the ALU an instruction code telling
it what to do. The ALU then performs all the calculations and stores the result in a different register,
which the CPU can read from and then continue the process.

Questions # 2. (10 Marks)

Differentiate the following terms.

• Half Duplex and Full Duplex Mode

A communications channel can be used to communicate one way at a time or in


both directions at once. The terms half-duplex and full-duplex describe these
transmission modes. Let's dig deeper to explore the difference between half-du-
plex and full-duplex.
What is half-duplex?
On a channel that is half-duplex, only one thing on that channel -- a node -- can "talk" or
transmit information at a time. Once one node has finished transmitting its data, another
node can start transmitting data. If multiple nodes try to talk at the same time, a collision
will occur on the network, resulting in transmission errors or data loss.

Half-duplex networks require a mechanism to avoid data collisions. Ethernet uses a


method called carrier sense multiple access with collision detection, or CSMA/CD. In
essence, an Ethernet device using half-duplex modes will first check to see if anything
else is transmitting before trying to send. If something else is sending, it will wait a ran-
dom amount of time before trying again.

What is full-duplex?
On the other hand, full-duplex is used to describe communication where two nodes talk-
ing to each other are able to send and receive data at the same time. In these cases, there
is no danger of a collision, and therefore, the transfer of data for any given communica-
tion is completed more quickly.

What are the key differences between half-duplex and full-duplex?


The main difference between half-duplex and full-duplex is simply whether communica-
tion happens in one direction at a time or in both directions simultaneously. Beyond that,
the differences center on use cases. Half-duplex, for example, can be used for media
shared by more than two nodes, while full-duplex generally cannot.

On a shared medium, such as a coaxial cable with several nodes attached to it, all the
nodes can share the channel because each knows to check if the channel is free before
sending. The tradeoff is efficiency. The more nodes that share the channel, the lower the
effective throughput for each node because of the increased time spent waiting for access.

Impact Printer and Non-Impact printer

Difference Between Impact And Non-Impact Printers


BASIS OF COM-
IMPACT PRINTERS NON-IMPACT PRINTERS
PARISON
Impact printers form images and Non-impact printers form char-
characters by striking a mecha- acters and images without di-
Description nism such as a print hammer or rect physical contact between
wheel against an inked ribbon, the printing mechanism and
leaving an image on paper. the paper.
Printing in impact printers is done Printing in non-impact printers
Printing Mecha-
by hammering a metal pin or char- is done by depositing ink on
nism
acter dye. paper in any form.
They are low speed printers. They
They are very fast, they can
Speed consume a lot of time to print a
print many pages per minute.
document.
They have high level of noise be- They do not have high level of
cause they have many moving noise. The process of laying
Noise Level
parts and also the print head ink or toner onto paper is vir-
strikes on ribbon and paper. tually silent.
They use pins, hammers or wheel They use laser, spray of spe-
Printing
to strike against an inked ribbon to cial ink or heat and pressure to
Process
print on a paper. print on paper.
Print quality of impact printers is Print quality of non-impact
Print Quality lower than those of non-impact printers is higher than those of
printers. impact printers.
They use special inked ribbons to
They use toner or cartridge for
Printing Ink produce print on paper when print
printing on paper.
head strikes.
They use latest printing tech-
Technology They use old printing technologies.
nologies.
They are often very expensive
Cost They are often less expensive. when compared to impact
printers.
Nature Of Pa-
They often use individual pa-
per Sheet They use continuous paper sheet.
per sheets.
Used
With exception of dot matrix Printing of graphical images in
Graphic Images printer, impact printers cannot non-impact printers is very
print graphics images. much possible.
With exception of dot matrix, the It can print different types of
Character Style character style cannot be changed characters form busing the in-
in the impact printers. dividual printer.

HDD and CD
Hard Disk
A hard disk drive (sometimes abbreviated as a hard drive, HD, or HDD) is a non-volatile data storage
device. It is usually installed internally in a computer, attached directly to the disk controller of the com-
puter’s motherboard. It contains one or more platters, housed inside of an air-sealed casing. Data is writ-
ten to the platters using a magnetic head, which moves rapidly over them as they spin.
Compact Disk
A compact disc is a flat, round, optical storage medium invented by James Russell. The first CD
was created at a Philips factory in Germany on August 17, 1982. The picture is an example of the bottom
of a standard compact disc and is the side the disc player reads. The opposite side of the disc has a label
to help indicate what is on the disc.

Difference between Hard Disk and Compact Disk

• Web Browsers and websites

Web browser
A internet browser (usually known as a browser) is a software utility for getting access to records at
the World Wide Web. When a person requests a web web page from a selected internet site, the net
browser retrieves the important content from an internet server and then presentations the page at the
display.
A internet browser isn't always the same component as a search engine, though the 2 are regularly
careworn.For a consumer, a seek engine is just a website, consisting of Google Search, Bing, or
DuckDuckGo, that stores searchable facts approximately different web sites. However, to connect to
a internet site's server and show its web pages, a person must have a web browser established.

Web browsers are used on a range of devices, including computers, laptops, tablets, and smart-
phones. In 2019, an envisioned four.Three billion humans used a browser.The maximum used
browser is Google Chrome, with a 64% worldwide market proportion on all gadgets, accompanied
by way of Safari with 17Function

The cause of an internet browser is to fetch records resources from the Web and display them on a
user's tool.

This procedure starts when the user inputs a Uniform Resource Locator (URL), inclusive of
https://en.Wikipedia.Org/, into the browser. Virtually all URLs on the Web start with both http: or
https: this means that the browser will retrieve them with the Hypertext Transfer Protocol (HTTP). In
the case of https:, the communication among the browser and the web server is encrypted for the
functions of safety and privacy.

Once a web web page has been retrieved, the browser's rendering engine presentations it on the con-
sumer's device. This consists of picture and video formats supported by means of the browser.Web
pages usually include hyperlinks to different pages and assets. Each link contains a URL, and whilst
it's far clicked or tapped, the browser navigates to the new resource. Thus the technique of bringing
content material to the user starts offevolved once more.

Most browsers use an internal cache of net web page resources to enhance loading times for subse-
quent visits to the same page. The cache can store many gadgets, consisting of large photos, so that
they do not need to be downloaded from the server once more.Cached gadgets are normally handiest
saved for so long as the net server stipulates in its HTTP reaction messages.

Settings
Web browsers can commonly be configured with a integrated menu. Depending on the browser, the
menu can be named Settings, Options, or Preferences.

The menu has exclusive varieties of settings. For example, customers can trade their domestic page
and default search engine. They can also exchange default web page colorings and fonts. Various
community connectivity and privateness settings are also usually to be had.

Privacy
During the route of surfing, cookies acquired from diverse web sites are saved by way of the
browser. Some of them incorporate login credentials or site preferences.[17] However, others are
used for monitoring person conduct over lengthy periods of time, so browsers usually provide set-
tings for getting rid of cookies when exiting the browser.[17] Finer-grained management of cookies
normally calls for a browser extension.[18]
Features
The most famous browsers have a number of features in not unusual. They permit customers to set
bookmarks and skim in a personal mode. They also can be custom designed with extensions, and
some of them provide a sync provider.

Most browsers have those user interface capabilities:

Allow the person to open a couple of pages at the equal time, either in unique browser windows or in
different tabs of the identical window.

Back and ahead buttons to move lower back to the previous web page visited or ahead to the next
one.

A refresh or reload button to reload the present day page.

A stop button to cancel loading the web page. (In some browsers, the forestall button is merged with
the reload button.)

A home button to go back to the consumer's domestic page.

An address bar to enter the URL of a web page and display it.

A search bar to input terms into a seek engine. (In a few browsers, the quest bar is merged with the
deal with bar.)

There are also niche browsers with wonderful capabilities. One instance is text-most effective
browsers that may advantage human beings with slow Internet connections or those with visual im-
pairments.

Website
.A internet site (also written as internet web site) is a set of net pages and associated content this is
recognized by way of a not unusual area name and posted on at least one net server. Notable exam-
ples are wikipedia.Org, google.Com, and amazon.Com.

All publicly on hand websites collectively represent the World Wide Web. There also are personal
web sites that could handiest be accessed on a non-public community, together with a organisation's
inner internet site for its employees.

Websites are typically committed to a selected topic or reason, along with information, schooling,
commerce, entertainment, or social networking. Hyperlinking between internet pages publications
the navigation of the site, which frequently starts with a domestic page.

Users can get admission to websites on a range of devices, inclusive of computers, laptops, capsules,
and smartphones. The software application used on these gadgets is referred to as an internet
browser.
Static website
A static internet site is one which has internet pages saved on the server inside the layout that is sent
to a customer net browser. It is mostly coded in Hypertext Markup Language (HTML); Cascading
Style Sheets (CSS) are used to govern appearance past simple HTML. Images are typically used to
effect the preferred appearance and as part of the principle content. Audio or video might also be
considered "static" content material if it performs mechanically or is generally non-interactive. This
type of website usually shows the equal data to all visitors. Similar to handing out a printed brochure
to customers or clients, a static website will generally offer consistent, fashionable facts for an pro-
longed period of time. Although the website proprietor may additionally make updates periodically,
it's miles a guide process to edit the textual content, pictures and different content material and might
require basic web site design capabilities and software. Simple paperwork or marketing examples of
websites, including classic website, a five-web page website or a brochure website are often static
websites, due to the fact they gift pre-defined, static facts to the consumer. This may encompass
records approximately a agency and its products and services thru text, images, animations, audio/
video, and navigation menus.

Static websites may still use server side consists of (SSI) as an modifying convenience, together with
sharing a not unusual menu bar across many pages. As the website online's behaviour to the reader is
still static, this is not considered a dynamic web site.

Dynamic internet site


A dynamic website is one which adjustments or customizes itself regularly and robotically. Server-
facet dynamic pages are generated "at the fly" through laptop code that produces the HTML (CSS
are answerable for look and thus, are static documents). There are a wide variety of software sys-
tems, which include CGI, Java Servlets and Java Server Pages (JSP), Active Server Pages and Cold-
Fusion (CFML) which can be to be had to generate dynamic internet systems and dynamic websites.
Various net utility frameworks and internet template structures are to be had for widespread-use pro-
gramming languages like Perl, PHP, Python and Ruby to make it quicker and less complicated to
create complex dynamic web sites.

A web page can show the modern kingdom of a talk between customers, display a changing situa-
tion, or provide facts in a few manner personalized to the requirements of the character person. For
example, while the front page of a news web page is requested, the code jogging at the web server
would possibly integrate stored HTML fragments with information tales retrieved from a database or
another internet site via RSS to provide a web page that includes the cutting-edge information. Dy-
namic websites may be interactive through the usage of HTML bureaucracy, storing and reading re-
turned browser cookies, or by way of developing a series of pages that replicate the previous history
of clicks. Another example of dynamic content material is whilst a retail internet site with a database
of media merchandise permits a person to input a search request, e.G. For the key-word Beatles. In
response, the content material of the web page will spontaneously change the manner it looked be-
fore, and will then display a list of Beatles merchandise like CDs, DVDs and books. Dynamic
HTML uses JavaScript code to train the net browser how to interactively modify the web page con-
tents. One way to simulate a certain type of dynamic internet site whilst heading off the overall per-
formance lack of starting up the dynamic engine on a consistent with-consumer or in keeping with-
connection foundation, is to periodically routinely regenerate a huge collection of static pages.

Questions # 3.

What is an Operating system? Briefly describe the scheduling techniques (1) First
Come First Serve (FCFS), (2) Shortest-Job-First (SJF) (3) Round Robin Sched-
uling using examples.

An operating system (OS) is system software that manages computer hardware, soft-
ware resources, and provides common services for computer programs.

Time-sharing operating systems schedule tasks for efficient use of the system and may
also include accounting software for cost allocation of processor time, mass storage,
printing, and other resources.

For hardware functions such as input and output and memory allocation, the operating
system acts as an intermediary between programs and the computer hardware,[1][2]
although the application code is usually executed directly by the hardware and fre-
quently makes system calls to an OS function or is interrupted by it. Operating sys-
tems are found on many devices that contain a computer – from cellular phones and
video game consoles to web servers and supercomputers.

The dominant desktop operating system is Microsoft Windows with a market share of
around 82.74%. macOS by Apple Inc. is in second place (13.23%), and the varieties of
Linux are collectively in third place (1.57%).[3] In the mobile sector (including smart-
phones and tablets), Android's share is up to 70% in the year 2017.[4] According to
third quarter 2016 data, Android's share on smartphones is dominant with 87.5 percent
with also a growth rate of 10.3 percent per year, followed by Apple's iOS with 12.1
percent with per year decrease in market share of 5.2 percent, while other operating
systems amount to just 0.3 percent.[5] Linux distributions are dominant in the server
and supercomputing sectors. Other specialized classes of operating systems, such as
embedded and real-time systems, exist for many applications.

Types of operating systems

Single-tasking and multi-tasking


A single-tasking system can only run one program at a time, while a multi-tasking op-
erating system allows more than one program to be running in concurrency. This is
achieved by time-sharing, where the available processor time is divided between mul-
tiple processes. These processes are each interrupted repeatedly in time slices by a
task-scheduling subsystem of the operating system. Multi-tasking may be character-
ized in preemptive and co-operative types. In preemptive multitasking, the operating
system slices the CPU time and dedicates a slot to each of the programs. Unix-like op-
erating systems, such as Solaris and Linux—as well as non-Unix-like, such as Ami-
gaOS—support preemptive multitasking. Cooperative multitasking is achieved by re-
lying on each process to provide time to the other processes in a defined manner. 16-
bit versions of Microsoft Windows used cooperative multi-tasking; 32-bit versions of
both Windows NT and Win9x used preemptive multi-tasking.

Single- and multi-user

Single-user operating systems have no facilities to distinguish users, but may allow
multiple programs to run in tandem.[6] A multi-user operating system extends the ba-
sic concept of multi-tasking with facilities that identify processes and resources, such
as disk space, belonging to multiple users, and the system permits multiple users to in-
teract with the system at the same time. Time-sharing operating systems schedule
tasks for efficient use of the system and may also include accounting software for cost
allocation of processor time, mass storage, printing, and other resources to multiple
users.

Distributed

A distributed operating system manages a group of distinct, networked computers and


makes them appear to be a single computer, as all computations are distributed (di-
vided amongst the constituent computers).[7]

Templated

In the distributed and cloud computing context of an OS, templating refers to creating
a single virtual machine image as a guest operating system, then saving it as a tool for
multiple running virtual machines. The technique is used both in virtualization and
cloud computing management, and is common in large server warehouses.[8]

Embedded

Embedded operating systems are designed to be used in embedded computer systems.


They are designed to operate on small machines with less autonomy (e.g. PDAs).
They are very compact and extremely efficient by design, and are able to operate with
a limited amount of resources. Windows CE and Minix 3 are some examples of em-
bedded operating systems.

Real-timeA real-time operating system is an operating system that guarantees to


process events or data by a specific moment in time. A real-time operating system may
be single- or multi-tasking, but when multitasking, it uses specialized scheduling algo-
rithms so that a deterministic nature of behavior is achieved. Such an event-driven sys-
tem switches between tasks based on their priorities or external events, whereas time-
sharing operating systems switch tasks based on clock interrupts.

Library

A library operating system is one in which the services that a typical operating system
provides, such as networking, are provided in the form of libraries and composed with
the application and configuration code to construct a unikernel: a specialized, single
address space, machine image that can be deployed to cloud or embedded environ-
ments.

FCFS Scheduling
First come first serve (FCFS) scheduling algorithm simply schedules the jobs according to
their arrival time. The job which comes first in the ready queue will get the CPU first. The lesser
the arrival time of the job, the sooner will the job get the CPU. FCFS scheduling may cause the
problem of starvation if the burst time of the first process is the longest among all the jobs.

Advantages of FCFS
o Simple
o Easy
o First come, First serv

Disadvantages of FCFS
1. The scheduling method is non preemptive, the process will run to the completion.
2. Due to the non-preemptive nature of the algorithm, the problem of starvation may occur.
3. Although it is easy to implement, but it is poor in performance since the average waiting
time is higher as compare to other scheduling algorithms.

Example
Let's take an example of The FCFS scheduling algorithm. In the Following schedule, there are 5
processes with process ID P0, P1, P2, P3 and P4. P0 arrives at time 0, P1 at time 1, P2 at time
2, P3 arrives at time 3 and Process P4 arrives at time 4 in the ready queue. The processes and
their respective Arrival and Burst time are given in the following table.

The Turnaround time and the waiting time are calculated by using the following formula.

1. Turn Around Time = Completion Time - Arrival Time


Waiting Time = Turnaround time - Burst Time

The average waiting Time is determined by summing the respective waiting time of all the pro-
cesses and divided the sum by the total number of processes.

Process ID Arrival Time Burst Time Completion Time Turn Around Time

0 0 2 2 2

1 1 6 8 7

2 2 4 12 8

3 3 9 21 18

4 4 12 33 29

Avg Waiting Time=31/5

What is Shortest Job First Scheduling?


Shortest Job First (SJF) is an algorithm in which the process having the small-
est 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.

There are basically two types of SJF methods:

 Non-Preemptive SJF
 Preemptive SJF
In this Operating System tutorial, you will learn:

 What is Shortest Job First Scheduling?


 Characteristics of SJF Scheduling
 Non-Preemptive SJF
 Preemptive SJF
 Advantages of SJF
 Disadvantages/Cons of SJF

Characteristics of SJF Scheduling


 It is associated with each job as a unit of time to complete.
 This algorithm method is helpful for batch-type processing, where waiting
for jobs to complete is not critical.
 It can improve process throughput by making sure that shorter jobs are ex-
ecuted first, hence possibly have a short turnaround time.
 It improves job output by offering shorter jobs, which should be executed
first, which mostly have a shorter turnaround time.

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

Consider the following five processes each having its own unique burst time and
arrival time.

Process Queue Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4
Step 0) At time=0, P4 arrives and starts execution.

Step 1) At time= 1, Process P3 arrives. But, P4 still needs 2 execution units to


complete. It will continue execution.

Step 2) At time =2, process P1 arrives and is added to the waiting queue. P4 will
continue execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time of P3 and
P1 is compared. Process P1 is executed because its burst time is less compared
to P3.

Step 4) At time = 4, process P5 arrives and is added to the waiting queue. P1 will
continue execution.

Step 5) At time = 5, process P2 arrives and is added to the waiting queue. P1 will
continue execution.
Step 6) At time = 9, process P1 will finish its execution. The burst time of P3, P5,
and P2 is compared. Process P2 is executed because its burst time is the lowest.

Step 7) At time=10, P2 is executing and P3 and P5 are in the waiting queue.

Step 8) At time = 11, process P2 will finish its execution. The burst time of P3
and P5 is compared. Process P5 is executed because its burst time is lower.
Step 9) At time = 15, process P5 will finish its execution.

Step 10) At time = 23, process P3 will finish its execution.

Step 11) Let's calculate the average waiting time for above example.

Wait time
P4= 0-0=0
P1= 3-2=1
P2= 9-5=4
P5= 11-4=7
P3= 15-1=14
Average Waiting Time= 0+1+4+7+14/5 = 26/5 = 5.2

Preemptive SJF
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 exe-
cution, and the shorter job is allocated CPU cycle.

Consider the following five process:

Process Queue Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

Step 0) At time=0, P4 arrives and starts execution.

Process Queue Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0
P5 4 4

Step 1) At time= 1, Process P3 arrives. But, P4 has a shorter burst time. It will
continue execution.

Step 2) At time = 2, process P1 arrives with burst time = 6. The burst time is
more than that of P4. Hence, P4 will continue execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time of P3 and
P1 is compared. Process P1 is executed because its burst time is lower.

Step 4) At time = 4, process P5 will arrive. The burst time of P3, P5, and P1 is
compared. Process P5 is executed because its burst time is lowest. Process P1
is preempted.

Process Queue Burst time Arrival time

P1 5 out of 6 is remaining 2

P2 2 5

P3 8 1

P4 3 0
P5 4 4

Step 5) At time = 5, process P2 will arrive. The burst time of P1, P2, P3, and P5
is compared. Process P2 is executed because its burst time is least. Process P5
is preempted.

Process Queue Burst time Arrival time

P1 5 out of 6 is remaining 2

P2 2 5

P3 8 1

P4 3 0

P5 3 out of 4 is remaining 4
Step 6) At time =6, P2 is executing.

Step 7) At time =7, P2 finishes its execution. The burst time of P1, P3, and P5 is
compared. Process P5 is executed because its burst time is lesser.

Process Queue Burst time Arrival time

P1 5 out of 6 is remaining 2

P2 2 5

P3 8 1

P4 3 0

P5 3 out of 4 is remaining 4
Step 8) At time =10, P5 will finish its execution. The burst time of P1 and P3 is
compared. Process P1 is executed because its burst time is less.

Step 9) At time =15, P1 finishes its execution. P3 is the only process left. It will
start execution.

Step 10) At time =23, P3 finishes its execution.


Step 11) Let's calculate the average waiting time for above example.

Wait time
P4= 0-0=0
P1= (3-2) + 6 =7
P2= 5-5 = 0
P5= 4-4+2 =2
P3= 15-1 = 14
Average Waiting Time = 0+7+0+2+14/5 = 23/5 =4.6

Advantages of SJF
Here are the benefits/pros of using SJF method:

 SJF is frequently used for long term scheduling.


 It reduces the average waiting time over FIFO (First in First Out) algorithm.
 SJF method gives the lowest average waiting time for a specific set of pro-
cesses.
 It is appropriate for the jobs running in batch, where run times are known in
advance.
 For the batch system of long-term scheduling, a burst time estimate can be
obtained from the job description.
 For Short-Term Scheduling, we need to predict the value of the next burst
time.
 Probably optimal with regard to average turnaround time.

Disadvantages/Cons of SJF
Here are some drawbacks/cons of SJF algorithm:

 Job completion time must be known earlier, but it is hard to predict.


 It is often used in a batch system for long term scheduling.
 SJF can't be implemented for CPU scheduling for the short term. It is be-
cause there is no specific method to predict the length of the upcoming
CPU burst.
 This algorithm may cause very long turnaround times or starvation.
 Requires knowledge of how long a process or job will run.
 It leads to the starvation that does not reduce average turnaround time.
 It is hard to know the length of the upcoming CPU request.
 Elapsed time should be recorded, that results in more overhead on the pro-
cessor.

Summary
 SJF is an algorithm in which the process having the smallest execution
time is chosen for the next execution.
 SJF Scheduling is associated with each job as a unit of time to complete.
 This algorithm method is helpful for batch-type processing, where waiting
for jobs to complete is not critical.
 There are basically two types of SJF methods 1) Non-Preemptive SJF and
2) Preemptive SJF.
 In non-preemptive scheduling, once the CPU cycle is allocated to process,
the process holds it till it reaches a waiting state or terminated.
 In Preemptive SJF Scheduling, jobs are put into the ready queue as they
come.
 Although a process with short burst time begins, the current process is re-
moved or preempted from execution, and the job which is shorter is exe-
cuted 1st.
 SJF is frequently used for long term scheduling.
 It reduces the average waiting time over FIFO (First in First Out) algorithm.
 In SJF scheduling, Job completion time must be known earlier, but it is
hard to predict.
 SJF can't be implemented for CPU scheduling for the short term. It is be-
cause there is no specific method to predict the length of the upcoming
CPU burst.

What is Round-Robin Scheduling?


The name of this algorithm comes from the round-robin principle, where each
person gets an equal share of something in turns. It is the oldest, simplest sched-
uling algorithm, which is mostly used for multitasking.

In Round-robin scheduling, each ready task runs turn by turn only in a cyclic
queue for a limited time slice. This algorithm also offers starvation free execution
of processes
Characteristics of Round-Robin Scheduling
Here are the important characteristics of Round-Robin Scheduling:

 Round robin is a pre-emptive algorithm


 The CPU is shifted to the next process after fixed interval time, which is
called time quantum/time slice.
 The process that is preempted is added to the end of the queue.
 Round robin is a hybrid model which is clock-driven
 Time slice should be minimum, which is assigned for a specific task that
needs to be processed. However, it may differ OS to OS.
 It is a real time algorithm which responds to the event within a specific time
limit.
 Round robin is one of the oldest, fairest, and easiest algorithm.
 Widely used scheduling method in traditional OS.

Example of Round-robin Scheduling


Consider this following three processes

Process Queue Burst time

P1 4

P2 3

P3 5
Step 1) The execution begins with process P1, which has burst time 4. Here, ev-
ery process executes for 2 seconds. P2 and P3 are still in the waiting queue.
Step 2) At time =2, P1 is added to the end of the Queue and P2 starts executing

Step 3) At time=4 , P2 is preempted and add at the end of the queue. P3 starts
executing.

Step 4) At time=6 , P3 is preempted and add at the end of the queue. P1 starts
executing.
Step 5) At time=8 , P1 has a burst time of 4. It has completed execution. P2
starts execution
Step 6) P2 has a burst time of 3. It has already executed for 2 interval. At time=9,
P2 completes execution. Then, P3 starts execution till it completes.

Step 7) Let's calculate the average waiting time for above example.

Wait time
P1= 0+ 4= 4
P2= 2+4= 6
P3= 4+3= 7

Advantage of Round-robin Scheduling


Here, are pros/benefits of Round-robin scheduling method:

 It doesn't face the issues of starvation or convoy effect.


 All the jobs get a fair allocation of CPU.
 It deals with all process without any priority
 If you know the total number of processes on the run queue, then you can
also assume the worst-case response time for the same process.
 This scheduling method does not depend upon burst time. That's why it is
easily implementable on the system.
Once a process is executed for a specific set of the period, the process is pre-
empted, and another process executes for that given time period.

 Allows OS to use the Context switching method to save states of pre-


empted processes.
 It gives the best performance in terms of average response time.

Disadvantages of Round-robin Scheduling


Here, are drawbacks/cons of using Round-robin scheduling:

 If slicing time of OS is low, the processor output will be reduced.


 This method spends more time on context switching
 Its performance heavily depends on time quantum.
 Priorities cannot be set for the processes.
 Round-robin scheduling doesn't give special priority to more important
tasks.
 Decreases comprehension
 Lower time quantum results in higher the context switching overhead in the
system.
 Finding a correct time quantum is a quite difficult task in this system.

Worst Case Latency


This term is used for the maximum time taken for execution of all the tasks.

 dt = Denote detection time when a task is brought into the list


 st = Denote switching time from one task to another
 et = Denote task execution time

Formula:
T
= {(dti+ sti + eti ), + (dti+ sti + eti )2 +...+ (dti+ sti + eti )N., + (dti+ sti
worst

+ eti + eti) N} + tISR


t,SR = sum of all execution times

Summary:
 The name of this algorithm comes from the round-robin principle, where
each person gets an equal share of something in turns.
 Round robin is one of the oldest, fairest, and easiest algorithms and widely
used scheduling methods in traditional OS.
 Round robin is a pre-emptive algorithm The biggest advantage of the
round-robin scheduling method is that If you know the total number of pro-
cesses on the run queue, then you can also assume the worst-case re-
sponse time for the same process.
 This method spends more time on context switching

Worst-case latency is a term used for the maximum time taken for the exe-
cution of all the tasks.

What is Transmission media?


o Transmission media is a communication channel that carries the information from
the sender to the receiver. Data is transmitted through the electromagnetic signals.
o The main functionality of the transmission media is to carry the information in the
form of bits through LAN(Local Area Network).
o It is a physical path between transmitter and receiver in data communication.
o In a copper-based network, the bits in the form of electrical signals.
o In a fibre based network, the bits in the form of light pulses.
o In OSI(Open System Interconnection) phase, transmission media supports the Layer
1. Therefore, it is considered to be as a Layer 1 component.
o The electrical signals can be sent through the copper wire, fibre optics, atmosphere,
water, and vacuum.
o The characteristics and quality of data transmission are determined by the charac-
teristics of medium and signal.
o Transmission media is of two types are wired media and wireless media. In wired
media, medium characteristics are more important whereas, in wireless media, sig-
nal characteristics are more important.
o Different transmission media have different properties such as bandwidth, delay,
cost and ease of installation and maintenance.
o The transmission media is available in the lowest layer of the OSI reference model,
i.e., Physical layer.

Some factors need to be considered for designing the transmission media:

o Bandwidth: All the factors are remaining constant, the greater the bandwidth of a
medium, the higher the data transmission rate of a signal.
o Transmission impairment: When the received signal is not identical to the transmitted
one due to the transmission impairment. The quality of the signals will get destroyed due
to transmission impairment.
o Interference: An interference is defined as the process of disrupting a signal when it
travels over a communication medium on the addition of some unwanted signal.

Causes Of Transmission Impairment:


o Attenuation: Attenuation means the loss of energy, i.e., the strength of the signal de-
creases with increasing the distance which causes the loss of energy.
o Distortion: Distortion occurs when there is a change in the shape of the signal. This
type of distortion is examined from different signals having different frequencies. Each
frequency component has its own propagation speed, so they reach at a different time
which leads to the delay distortion.
o Noise: When data is travelled over a transmission medium, some unwanted signal is
added to it which creates the noise.

Classification Of Transmission Media:

1. Guided Media:
It is also referred to as Wired or Bounded transmission media. Signals being transmitted
are directed and confined in a narrow pathway by using physical links.

Features:
 High Speed
 Secure
 Used for comparatively shorter distances
There are 3 major types of Guided Media:
(i) Twisted Pair Cable –
It consists of 2 separately insulated conductor wires wound about each other. Generally,
several such pairs are bundled together in a protective sheath. They are the most widely
used Transmission Media. Twisted Pair is of two types:
1. Unshielded Twisted Pair (UTP):
This type of cable has the ability to block interference and does not depend on a phys-
ical shield for this purpose. It is used for telephonic applications.
Advantages:
 Least expensive
 Easy to install
 High speed capacity
Disadvantages:
 Susceptible to external interference
 Lower capacity and performance in comparison to STP
 Short distance transmission due to attenuation
2. Shielded Twisted Pair (STP):
This type of cable consists of a special jacket to block external interference. It is used
in fast-data-rate Ethernet and in voice and data channels of telephone lines.
Advantages:
 Better performance at a higher data rate in comparison to UTP
 Eliminates crosstalk
 Comparitively faster
Disadvantages:
 Comparitively difficult to install and manufacture
 More expensive
 Bulky
(ii) Coaxial Cable –
It has an outer plastic covering containing 2 parallel conductors each having a separate in-
sulated protection cover. Coaxial cable transmits information in two modes: Baseband
mode(dedicated cable bandwidth) and Broadband mode(cable bandwidth is split into sepa-
rate ranges). Cable TVs and analog television networks widely use Coaxial cables.

Advantages:
 High Bandwidth
 Better noise Immunity
 Easy to install and expand
 Inexpensive
Disadvantages:
 Single cable failure can disrupt the entire network
(iii) Optical Fibre Cable –
It uses the concept of reflection of light through a core made up of glass or plastic. The core
is surrounded by a less dense glass or plastic covering called the cladding. It is used for
transmission of large volumes of data.
Advantages:
 Increased capacity and bandwidth
 Light weight
 Less signal attenuation
 Immunity to electromagnetic interference
 Resistance to corrosive materials
Disadvantages:
 Difficult to install and maintain
 High cost
 Fragile
 unidirectional, ie, will need another fibre, if we need bidirectional communication
2. Unguided Media:
It is also referred to as Wireless or Unbounded transmission media.No physical medium is
required for the transmission of electromagnetic signals.
Features:
 Signal is broadcasted through air
 Less Secure
 Used for larger distances
There are 3 major types of Unguided Media:
(i) Radiowaves –
These are easy to generate and can penetrate through buildings. The sending and receiv-
ing antennas need not be aligned. Frequency Range:3KHz – 1GHz. AM and FM radios and
cordless phones use Radiowaves for transmission.
Further Categorized as (i) Terrestrial and (ii) Satellite.
(ii) Microwaves –
It is a line of sight transmission i.e. the sending and receiving antennas need to be properly
aligned with each other. The distance covered by the signal is directly proportional to the
height of the antenna. Frequency Range:1GHz – 300GHz. These are majorly used for mo-
bile phone communication and television distribution.
(iii) Infrared –
Infrared waves are used for very short distance communication. They cannot penetrate
through obstacles. This prevents interference between systems. Frequency Range:300GHz
– 400THz. It is used in TV remotes, wireless mouse, keyboard, printer, etc.
GeeksforGeeks has prepared a complete interview preparation course with premium
videos, theory, practice problems, TA support and many more features. Please refer Place-
ment 100 for detail

Questions # 5.
Write short notes on the following topics:
• Transmission Media
• Volatile Memory
• Internet
• DBMS

Transmission media
A transmission medium is something that can mediate the propagation of signals for the
purposes of telecommunication.Signals are typically imposed on a wave of some kind
suitable for the chosen medium. For example, data can modulate sound and a transmis-
sion medium for sounds may be air, but solids and liquids may also act as the transmis-
sion medium. Vacuum or air constitutes a good transmission medium for electromagnetic
waves such as light and radio waves. While material substance is not required for electro-
magnetic waves to propagate, such waves are usually affected by the transmission media
they pass through, for instance by absorption or by reflection or refraction at the inter-
faces between media. Technical devices can therefore be employed to transmit or guide
waves. Thus, an optical fiber or a copper cable are used as transmission media.

Volatile memory

Volatile memory in contrast to non-volatile memory, is computer memory that requires


power to maintain the stored information; it retains its contents while powered on but
when the power is interrupted, the stored data is quickly lost.

Volatile memory has several uses including as primary storage. In addition to usually be-
ing faster than forms of mass storage such as a hard disk drive, volatility can protect sen-
sitive information, as it becomes unavailable on power-down. Most of the general-pur-
pose random-access memory (RAM) is volatile

Types

There are two kinds of volatile RAM: dynamic and static. Even though both types need
continuous electrical current to retain data, there are some important differences between
them.

Dynamic RAM (DRAM) is very popular due to its cost effectiveness. DRAM stores each
bit of information in a different capacitor within the integrated circuit. DRAM chips need
just one single capacitor and one transistor to store each bit of information. This makes it
space efficient and inexpensive.

The main advantage of static RAM (SRAM) is that it is much faster than dynamic RAM.
Its disadvantage is its high price. SRAM does not need continuous electrical refreshes,
but it still requires constant current to sustain the difference in voltage. Every single bit in
a static RAM chip needs a cell of six transistors, whereas dynamic RAM requires only
one capacitor and one transistor. As a result, SRAM is unable to accomplish the storage
capabilities of the DRAM family,SRAM is commonly used as CPU cache and for proces-
sor registers and in networking device

Internet The Internet is the global system of interconnected computer networks that uses
the Internet protocol suite (TCP/IP) to communicate between networks and devices. It is a
network of networks that consists of private, public, academic, business, and government
networks of local to global scope, linked by a broad array of electronic, wireless, and op-
tical networking technologies. The Internet carries a vast range of information resources
and services, such as the inter-linked hypertext documents and applications of the World
Wide Web (WWW), electronic mail, telephony, and file sharing.

The origins of the Internet date back to the development of packet switching and research
commissioned by the United States Department of Defense in the 1960s to enable time-
sharing of computers.[1] The primary precursor network, the ARPANET, initially served
as a backbone for interconnection of regional academic and military networks in the
1970s. The funding of the National Science Foundation Network as a new backbone in
the 1980s, as well as private funding for other commercial extensions, led to worldwide
participation in the development of new networking technologies, and the merger of
many networks.[2] The linking of commercial networks and enterprises by the early
1990s marked the beginning of the transition to the modern Internet,[3] and generated a
sustained exponential growth as generations of institutional, personal, and mobile com-
puters were connected to the network. Although the Internet was widely used by
academia in the 1980s, commercialization incorporated its services and technologies into
virtually every aspect of modern life.

Most traditional communication media, including telephony, radio, television, paper mail
and newspapers are reshaped, redefined, or even bypassed by the Internet, giving birth to
new services such as email, Internet telephony, Internet television, online music, digital
newspapers, and video streaming websites. Newspaper, book, and other print publishing
are adapting to website technology, or are reshaped into blogging, web feeds and online
news aggregators. The Internet has enabled and accelerated new forms of personal inter-
actions through instant messaging, Internet forums, and social networking. Online shop-
ping has grown exponentially both for major retailers and small businesses and en-
trepreneurs, as it enables firms to extend their "brick and mortar" presence to serve a
larger market or even sell goods and services entirely online. Business-to-business and fi-
nancial services on the Internet affect supply chains across entire industries.

The Internet has no single centralized governance in either technological implementation


or policies for access and usage; each constituent network sets its own policies.[4] The
overreaching definitions of the two principal name spaces in the Internet, the Internet Pro-
tocol address (IP address) space and the Domain Name System (DNS), are directed by a
maintainer organization, the Internet Corporation for Assigned Names and Numbers
(ICANN). The technical underpinning and standardization of the core protocols is an ac-
tivity of the Internet Engineering Task Force (IETF), a non-profit organization of loosely
affiliated international participants that anyone may associate with by contributing techni-
cal expertise.In November 2006, the Internet was included on USA Today's list of New
Seven Wonders.

What is a Database?
A database is a collection of related data which represents some aspect of the real world.
A database system is designed to be built and populated with data for a certain task.

What is DBMS?

Database Management System (DBMS) is a software for storing and retrieving users' data
while considering appropriate security measures. It consists of a group of programs which
manipulate the database. The DBMS accepts the request for data from an application and
instructs the operating system to provide the specific data. In large systems, a DBMS
helps users and other third-party software to store and retrieve data.

DBMS allows users to create their own databases as per their requirement. The term
“DBMS” includes the user of the database and other application programs. It provides an
interface between the data and the software application.

example of a university database. This database is maintaining information concerning


students, courses, and grades in a university environment. The database is organized as
five files:

The STUDENT file stores data of each student

The COURSE file stores contain data on each course.

The SECTION stores the information about sections in a particular course.

The GRADE file stores the grades which students receive in the various sections

The TUTOR file contains information about each professor.

To define a database system:

We need to specify the structure of the records of each file by defining the different types
of data elements to be stored in each record.

We can also use a coding scheme to represent the values of a data item.

Basically, your Database will have 5 tables with a foreign key defined amongst the vari-
ous tables.

Characteristics of Database Management System

Provides security and removes redundancy

Self-describing nature of a database system


Insulation between programs and data abstraction

Support of multiple views of the data

Sharing of data and multiuser transaction processing

DBMS allows entities and relations among them to form tables.

It follows the ACID concept ( Atomicity, Consistency, Isolation, and Durability).

DBMS supports multi-user environment that allows users to access and manipulate data
in parallel.

Advantages of DBMS

DBMS offers a variety of techniques to store & retrieve data

DBMS serves as an efficient handler to balance the needs of multiple applications using
the same data

Uniform administration procedures for data

Application programmers never exposed to details of data representation and storage.

A DBMS uses various powerful functions to store and retrieve data efficiently.

Offers Data Integrity and Security

The DBMS implies integrity constraints to get a high level of protection against prohib-
ited access to data.

A DBMS schedules concurrent access to the data in such a manner that only one user can
access the same data at a time

Reduced Application Development Time

Disadvantage of DBMS

DBMS may offer plenty of advantages but, it has certain flaws-Cost of Hardware and
Software of a DBMS is quite high which increases the budget of your organization.

Most database management systems are often complex systems, so the training for users
to use the DBMS is required.

In some organizations, all data is integrated into a single database which can be damaged
because of electric failure or database is corrupted on the storage media
Use of the same program at a time by many users sometimes lead to the loss of some
data.

DBMS can't perform sophisticated calculations

You might also like