OS Unit1
OS Unit1
1
Collected by Bipin Timalsina
Unit-1/OS
Here we see the hardware at the bottom. On top of the hardware is the software.
Most computers have two modes of operation: kernel mode and user mode.
2
Collected by Bipin Timalsina
Unit-1/OS
The operating system, the most fundamental piece of software, runs in kernel mode
(also called supervisor mode).
In this mode it has complete access to all the hardware and can execute any
instruction the machine is capable of executing.
The rest of the software runs in user mode, in which only a subset of the machine instructions
is available.
In particular, those instructions that affect control of the machine or do I/O ) Input/Output" are
forbidden to user-mode programs.
The user interface program, shell or GUI, is the lowest level of user-mode software, and allows
the user to start other programs, such as a Web browser, email reader, or music player. These
programs, too, make heavy use of the operating system.
The placement of the operating system is shown in above figures. It runs on the bare
hardware and provides the base for all the other software.
Roles of OS
Implementing the user interface
Sharing hardware among users
Allowing users to share data among themselves
Preventing users from interfering with one another
Scheduling resources among users
Facilitating input/output
Recovering from errors
Accounting for resource usage
Facilitating parallel operations
Organizing data for secure and rapid access
Handling network communications
3
Collected by Bipin Timalsina
Unit-1/OS
It is hard to pin down what an operating system is other than saying it is the software that runs in
kernel mode—and even that is not always true.
4
Collected by Bipin Timalsina
Unit-1/OS
In contrast, end users deal with the abstractions provided by the user interface, either
a command- line shell or a graphical interface. While the abstractions at the user
interface may be similar to the ones provided by the operating system, this is not always
the case. To make this point clearer, consider the normal Windows desktop and the line-
oriented command prompt. Both are programs running on the Windows operating system
and use the abstractions Windows provides, but they offer very different user interfaces.
5
Collected by Bipin Timalsina
Unit-1/OS
o For example, with only one CPU and multiple programs that want to run on it, the
operating system first allocates the CPU to one program, then, after it has run long
enough, another program gets to use the CPU, then another, and then eventually the
first one again.
o Determining how the resource is time multiplexed—who goes next and for how
long—is the task of the operating system.
o Another example of time multiplexing is sharing the printer.
When multiple print jobs are queued up for printing on a single printer, a
decision has to be made about which one is to be printed next.
In space multiplexing, instead of the customers taking a chance, each one gets part of the
resource.
o For example − Main memory is divided into several running programs, so each one
can be resident at the same time.
o Another resource that is space multiplexed is the disk. In many systems a single
disk can hold files from many users at the same time. Allocating disk space and
keeping track of who is using which disk blocks is a typical operating system task.
6
Collected by Bipin Timalsina
Unit-1/OS
By the early 1950's, the routine had improved somewhat with the introduction of punch
cards.
The General Motors Research Laboratories implemented the first operating systems in
early 1950's for their IBM 701.
The system of the 50's generally ran one job at a time. These were called single-stream
batch processing systems because programs and data were submitted in groups or batches.
The systems of the 1960's were also batch processing systems, but they were able to take
better advantage of the computer's resources by running several jobs at once.
So operating systems designers developed the concept of multiprogramming in which
several jobs are in main memory at once; a processor is switched from job to job as needed
to keep several jobs advancing while keeping the peripheral devices in use.
• For example, on the system with no multiprogramming, when the current job
paused to wait for other I/O operation to complete, the CPU simply sat idle until
the I/O finished.
• The solution for this problem that evolved was to partition memory into several
pieces, with a different job in each partition. While one job was waiting for I/O to
complete, another job could be using the CPU.
Another major feature in third-generation operating system was the technique called
spooling (simultaneous peripheral operations on line).
• In spooling, a high-speed device like a disk interposed between a running program
and a low-speed device involved with the program in input/output.
• Instead of writing directly to a printer, for example, outputs are written to the disk.
• Programs can run to completion faster, and other programs can be initiated sooner
when the printer becomes available, the outputs may be printed.
Another feature present in this generation was time-sharing technique, a variant of
multiprogramming technique, in which each user has an on-line (i.e., directly connected)
terminal. Because the user is present and interacting with the computer, the computer
system must respond quickly to user requests, otherwise user productivity could suffer.
Timesharing systems were developed to multiprogram large number of simultaneous
interactive users.
7
Collected by Bipin Timalsina
Unit-1/OS
The first general-purpose timesharing system, CTSS (Compatible Time Sharing System),
was developed at M.I.T.
MULTICS (MULTiplexed Information and Computing Service)
With the development of LSI (Large Scale Integration) circuits, chips, operating system
entered in the system entered in the personal computer and the workstation age.
Microprocessor technology evolved to the point that it becomes possible to build desktop
computers as powerful as the mainframes of the 1970s.
Two operating systems have dominated the personal computer scene: MS-DOS, written by
Microsoft, Inc. for the IBM PC and other machines using the Intel 8088 CPU and its
successors, and UNIX, which is dominant on the large personal computers using the
Motorola 6899 CPU family.
MAC OSX , Windows 95, Windows NT, Windows 98, Windows 200, Windows Me
Windows XP, Windows 7, Windows 8, Windows 10, Windows11
The first real mobile phone appeared in 1946 and weighed some 40 kilos. You could take
it wherever you went as long as you had a car in which to carry it.
The first true handheld phone appeared in the 1970s and, at roughly one kilogram, was
positively featherweight. It was affectionately known as ‘‘the brick.’’
Pretty soon everybody wanted one. Today, mobile phone penetration is close to 90% of the
global population. We can make calls not just with our portable phones and wrist watches,
but soon with eyeglasses and other wearable items. Moreover, the phone part is no longer
that interesting. We receive email, surf the Web, text our friends, play games, navigate
around heavy traffic—and do not even think twice about it.
While the idea of combining telephony and computing in a phone-like device has been
around since the 1970s also, the first real smartphone did not appear until the mid-1990s
when Nokia released the N9000, which literally combined two, mostly separate devices: a
phone and a PDA (Personal Digital Assistant). In 1997, Ericsson coined the term
smartphone for its GS88 ‘‘Penelope.’’
Mobile phones, Smartphones
Symbian OS, Blackberry OS, Android OS, iOS
8
Collected by Bipin Timalsina
Unit-1/OS
9
Collected by Bipin Timalsina
Unit-1/OS
10
Collected by Bipin Timalsina
Unit-1/OS
You cannot download new applications to your microwave oven—all the software is in
ROM. This means that there is no need for protection between applications, leading to
design simplification.
Systems such as Embedded Linux, QNX and VxWorks are popular in this domain.
7. Sensor-Node Operating Systems
Networks of tiny sensor nodes are being deployed for numerous purposes. These nodes are
tiny computers that communicate with each other and with a base station using wireless
communication.
Sensor networks are used to protect the perimeters of buildings, guard national borders,
detect fires in forests, measure temperature and precipitation for weather forecasting, glean
information about enemy movements on battlefields, and much more.
Each sensor node is a real computer, with a CPU, RAM, ROM, and one or more
environmental sensors. It runs a small, but real operating system, usually one that is event
driven, responding to external events or making measurements periodically based on an
internal clock.
The operating system has to be small and simple because the nodes have little RAM and
battery lifetime is a major issue.
Also, as with embedded systems, all the programs are loaded in advance; users do not
suddenly start programs they downloaded from the Internet, which makes the design much
simpler.
TinyOS is a well-known operating system for a sensor node.
8. Real-Time Operating Systems
These systems are characterized by having time as a key parameter. For example, in
industrial process- control systems, real-time computers have to collect data about the
production process and use it to control machines in the factory.
Often there are hard deadlines that must be met. For example, if a car is moving down an
assembly line, certain actions must take place at certain instants of time.
o If, for example, a welding robot welds too early or too late, the car will be ruined.
o If the action absolutely must occur at a certain moment (or within a certain range),
we have a hard real-time system.
o These systems must provide absolute guarantees that a certain action will occur by
a certain time.
11
Collected by Bipin Timalsina
Unit-1/OS
A soft real-time system, is one where missing an occasional deadline, while not desirable,
is acceptable and does not cause any permanent damage.
Digital audio or multimedia systems fall in this category. Smartphones are also soft real-
time systems.
NOTE: The embedded and real-time systems run only software put in by the system designers;
users cannot add their own software, which makes protection easier. The handhelds and
embedded systems are intended for consumers, whereas real-time systems are more for
industrial usage.
System Call
A system call is a mechanism that provides the interface between a process and the
operating system. It is a programmatic method in which a computer program requests a
service from the kernel of the OS.
The interface between a process and an operating system is provided by system call
System calls are usually made when a process in user mode requires access to a resource.
Then it requests the kernel to provide the resource via a system call.
12
Collected by Bipin Timalsina
Unit-1/OS
As can be seen from above diagram, the processes execute normally in the user mode until a system
call interrupts this. Then the system call is executed on a priority basis in the kernel mode. After
the execution of the system call, the control returns to the user mode and execution of user
processes can be resumed.
If a file system requires the creation or deletion of files. Reading and writing from files
also require a system call.
Creation and management of new processes.
Network connections also require system calls. This includes sending and receiving
packets.
Access to a hardware devices such as a printer, scanner etc. requires a system call.
It has three parameters: the first one specifying the file, the second one pointing to the buffer, and
the third one giving the number of bytes to read.
13
Collected by Bipin Timalsina
Unit-1/OS
System calls are performed in a series of steps. The steps in read system call are as follows :
In preparation for calling the read library procedure, which actually makes the read system
call, the calling program first pushes the parameters onto the stack, as shown in steps 1–3
in following figure.
The first and third parameters are called by value, but the second parameter is passed by
reference, meaning that the address of the buffer (indicated by &) is passed, not the contents
of the buffer. Then comes the actual call to the library procedure (step 4). This instruction
is the normal procedure- call instruction used to call all procedures.
The library procedure, possibly written in assembly language, typically puts the system-
call number in a place where the operating system expects it, such as a register (step 5).
Then it executes a TRAP instruction to switch from user mode to kernel mode and start
execution at a fixed address within the kernel (step 6).
o The TRAP instruction is actually fairly similar to the procedure-call instruction in
the sense that the instruction following it is taken from a distant location and the
return address is saved on the stack for use later.
o Nevertheless, the TRAP instruction also differs from the procedure-call instruction
in two fundamental ways.
First, as a side effect, it switches into kernel mode. The procedure call
instruction does not change the mode.
Second, rather than giving a relative or absolute address where the
procedure is located, the TRAP instruction cannot jump to an arbitrary
address.
The kernel code that starts following the TRAP examines the system-call number and then
dispatches to the correct system-call handler, usually via a table of pointers to system-call
handlers indexed on system-call number (step 7).
At that point the system-call handler runs (step 8).
Once it has completed its work, control may be returned to the user-space library procedure
at the instruction following the TRAP instruction (step 9).
This procedure then returns to the user program in the usual way procedure calls return
(step 10).
To finish the job, the user program has to clean up the stack, as it does after any procedure
call (step 11).
14
Collected by Bipin Timalsina
Unit-1/OS
Figure : The 11 steps in making the system call read(fd, buffer, nbytes).
15
Collected by Bipin Timalsina
Unit-1/OS
System Calls
Process These system calls deal with processes such as process creation,
Management process termination etc.
File Management These system calls are responsible for file manipulation such as
creating a file, reading a file, writing into a file etc.
Directory These system calls are responsible for system calls that are related
Management to directories or the file system like creating new directory,
mounting filesystem etc.
Miscellaneous Other different system calls for different tasks
16
Collected by Bipin Timalsina
Unit-1/OS
Miscellaneous
17
Collected by Bipin Timalsina
Unit-1/OS
System programs
System programs provide an environment where programs can be developed and executed.
Also called system software.
In the simplest sense, system programs also provide a bridge between the user interface
and system calls. In reality, they are much more complex. For example, a compiler is a
complex system program.
The system program serves as a part of the operating system. It traditionally lies between
the user interface and the system calls.
System programs interacts with operating system through system calls. Sometimes it is
also called as collection of system calls.
The user view of the system is actually defined by system programs and not system calls
because that is what they interact with and system programs are closer to the user interface.
System programs as well as application programs form a bridge between the user interface
and the system calls. So, from the user view the operating system observed is actually the
system programs and not the system calls.
18
Collected by Bipin Timalsina
Unit-1/OS
File Management
These system programs are used to manipulate files in a system. This can be done using
various commands like create, delete, copy, rename, print etc. These commands can create
files, delete files, copy the contents of one file into another, rename files, print them etc.
They are used to list, and generally manipulate files and directories.
Status information
The status information system programs provide required data on the current or past status
of the system.
This may include the system date, system time, available space in memory or disk space,
logged in users, detailed performance, logging, and debugging information etc.
File Modification
System programs that are used for file modification basically change the data in the file or
modify it in some other way.
For Files stored on disks or other storage devices, we used different types of editors. For
searching contents of files or perform transformations of files we use special commands
Example: Text Editors
Programming-Language support
These system programs provide additional support features for different programming
languages. Some examples of these are compilers, assemblers, interpreters, debuggers etc.
These compile a program and make sure it is error free respectively.
Communication
These programs provide connection among processes, users, and computer systems. Users
can send messages to another user on their screen, user can send e-mail, browsing on web
pages, remote login, the transformation of files from one user to another
Provides system communications.
19
Collected by Bipin Timalsina
Unit-1/OS
The system programs that deal with program loading and execution make sure that
programs can be loaded into memory and executed correctly.
Loaders and Linkers are a prime example of this type of system programs.
Monolithic Systems
By far the most common organization, in the monolithic approach the entire operating system
runs as a single program in kernel mode.
The operating system is written as a collection of procedures, linked together into a single large
executable binary program.
The OS in it is written as a collection of procedures, each of which can call any of the other
ones whenever it needs to.
In this technique each procedure is free to call any other one, if the latter provides some useful
computation than the former needs.
To construct the actual object of the operating system when this approach is used, one first
compiles all the individuals' procedures, or files containing the procedures and then binds them
all together into a single object file using the system linker.
In terms of information hiding, there is essentially none – every procedure is visible to every
other procedure.
Even in monolithic systems, however, it is possible to have some structure.
o The services (system calls) provided by the operating system are requested by putting
the parameters in a well-defined place (e.g., on the stack) and then executing a trap
instruction.
o This instruction switches the machine from user mode to kernel mode and transfers
control to the operating system
o The operating system then fetches the parameters and determines which system call is
to be carried out. After that, it indexes into a table that contains in slot k a pointer to
the procedure that carries out system call k
20
Collected by Bipin Timalsina
Unit-1/OS
Layered Systems
To generalize the monolithic system into the hierarchy of layers, the first system called THE
was built by E.W. Dijkstra in 1986.
This system had 6 layers.
21
Collected by Bipin Timalsina
Unit-1/OS
An OS can be broken into pieces and retain much more control on system. In this structure
the OS is broken into number of layers (levels)
Microkernels
With the layered approach, the designers have a choice where to draw the kernel- user
boundary. Traditionally, all the layers went in the kernel, but that is not necessary.
o In fact, a strong case can be made for putting as little as possible in kernel mode
because bugs in the kernel can bring down the system instantly.
o In contrast, user processes can be set up to have less power so that a bug there may
not be fatal.
The basic idea behind the microkernel design is to achieve high reliability by splitting the
operating system up into small, well-defined modules, only one of which—the
microkernel—runs in kernel mode and the rest run as relatively powerless ordinary user
processes.
o In particular, by running each device driver and file system as a separate user
process, a bug in one of these can crash that component, but cannot crash the entire
system.
o Thus a bug in the audio driver will cause the sound to be garbled or stop, but will
not crash the computer.
o In contrast, in a monolithic system with all the drivers in the kernel, a buggy audio
driver can easily reference an invalid memory address and bring the system to a
grinding halt instantly
The process structure of MINIX 3 is shown in the figure, with the kernel call handlers
labeled Sys. The device driver for the clock is also in the kernel because the scheduler
interacts closely with it. The other device drivers run as separate user processes.
Outside the kernel, the system is structured as three layers of processes all running in user
mode.
o The lowest layer contains the device drivers. Since they run in user mode, they do
not have physical access to the I/O port space and cannot issue I/O commands
directly. Instead, to program an I/O device, the driver builds a structure telling
which values to write to which I/O ports and makes a kernel call telling the kernel
22
Collected by Bipin Timalsina
Unit-1/OS
to do the write. This approach means that the kernel can check to see that the driver
is writing (or reading) from I/O it is authorized to use. Consequently (and unlike a
monolithic design), a buggy audio driver cannot accidentally write on the disk.
o Above the drivers is another user-mode layer containing the servers, which do most
of the work of the operating system. One or more file servers manage the file
system(s), the process manager creates, destroys, and manages processes, and so
on.
o User programs obtain operating system services by sending short messages to the
servers asking for the POSIX system calls..
An idea somewhat related to having a minimal kernel is to put the mechanism for doing
something in the kernel but not the policy.
o To make this point better, consider the scheduling of processes. A relatively simple
scheduling algorithm is to assign a numerical priority to every process and then
have the kernel run the highest-priority process that is runnable.
o The mechanism—in the kernel—is to look for the highest-priority process and run
it.
o The policy—assigning priorities to processes—can be done by user-mode
processes.
23
Collected by Bipin Timalsina
Unit-1/OS
o In this way, policy and mechanism can be decoupled and the kernel can be made
smaller
Microkernels
• Small number of processes are allowed in the kernel
• Minimizes effects of bugs
Don’t want bug in driver to crash system
• Put mechanism in kernel and policy outside the kernel
Mechanism- schedule processes by priority scheduling algorithm
Policy-assign process priorities in user space
• Policy and mechanism can be decoupled and the kernel can be made smaller
•
Client-Server Model
• A slight variation of the microkernel idea is to distinguish two classes of processes, the
servers, each of which provides some service, and the clients, which use these services.
This model is known as the client-server model.
• Since clients communicate with servers by sending messages, the clients need not know
whether the messages are handled locally on their own machines, or whether they are sent
across a network to servers on a remote machine.
o As far as the client is concerned, the same thing happens in both cases: requests are
sent and replies come back.
o Thus the client-server model is an abstraction that can be used for a single machine
or for a network of machines.
• .Increasingly many systems involve users at their home PCs as clients and large machines
elsewhere running as servers. In fact, much of the Web operates this way. A PC sends a
request for a Web page to the server and the Web page comes back. This is a typical use
of the client server model in a network.
24
Collected by Bipin Timalsina
Unit-1/OS
Virtual Machines
The concept of a virtual machine is to provide an interface that looks like independent
hardware, to multiple different OSes running simultaneously on the same physical hardware.
Each OS believes that it has access to and control over its own CPU, RAM, I/O devices, hard
drives, etc.
One obvious use for this system is for the development and testing of software that must run
on multiple platforms and/or OSes.
One obvious difficulty involves the sharing of hard drives, which are generally partitioned into
separate smaller virtual disks for each operating OS.
NOTES:
Virtual machines are made possible through virtualization technology. Virtualization uses
software to simulate virtual hardware that allows multiple VMs to run on a single machine.
The physical machine is known as the host while the VMs running on it are called guests.
This process is managed by software known as a hypervisor. The hypervisor is responsible
for managing and provisioning resources—like memory and storage—from the host to
guests. It also schedules operations in VMs so they don’t overrun each other when using
resources. VMs only work if there is a hypervisor to virtualize and distribute host resources
26
Collected by Bipin Timalsina
Unit-1/OS
Exokernels
Rather than cloning the actual machine, as is done with virtual machines, another strategy
is partitioning it, in other words, giving each user a subset of the resources. Thus one virtual
machine might get disk blocks 0 to 1023, the next one might get blocks 1024 to 2047, and
so on. At the bottom layer, running in kernel mode, is a program called the exokernel. Its
job is to allocate resources to virtual machines and then check attempts to use them to make
sure no machine is trying to use somebody else’s resources.
The advantage of the exokernel scheme is that it saves a layer of mapping. In the other
designs, each virtual machine thinks it has its own disk, with blocks running from 0 to
some maximum, so the virtual machine monitor must maintain tables to remap disk
addresses (and all other resources). With the exokernel, this remapping is not needed. The
exokernel need only keep track of which virtual machine has been assigned which resource.
This method still has the advantage of separating the multiprogramming (in the exokernel)
from the user operating system code (in user space), but with less overhead, since all the
exokernel has to do is keep the virtual machines out of each other’s hair.
Research task: The structures of OSes (latest stable versions) like iOS, Android, Ubuntu, Windows
10 /11 , Mac OS
The Shell
A shell is software that provides an interface between users and operating system of
a computer to access the services of a kernel.
It is named a shell because it is the outermost layer around the operating system
The shell is the outermost layer of the operating system which provide a way to
communicate with the operating system. This communication is carried out either
interactively (input from the keyboard is acted upon immediately) or as a shell script.
A shell script is a sequence of shell and operating system commands that is stored in a file.
Operating system shells generally fall into one of two categories: command-line and
graphical.
Command-line shells provide a command-line interface (CLI) to the operating system,
while graphical shells provide a graphical user interface (GUI)
Command-line shells require the user to be familiar with commands and their
calling syntax, and to understand concepts about the shell-specific scripting language (for
27
Collected by Bipin Timalsina
Unit-1/OS
example, bash). Graphical shells place a low burden on beginning computer users, and are
characterized as being easy to use. Since they also come with certain disadvantages, most
GUI-enabled operating systems also provide CLI shells.
In either category the primary purpose of the shell is to invoke or "launch" another
program; however, shells frequently have additional capabilities such as viewing the
contents of directories.
Examples :
Windows Shell (GUI)
CommandPromt , PowerShell (Windows CLI:)
Linux CLI
28
Collected by Bipin Timalsina