OS Unit-1 Notes
OS Unit-1 Notes
UNIT-I
Operating System - Introduction, Structures - Simple Batch, Multiprogrammed,
Time-shared,PersonalComputer,Parallel,DistributedSystems,Real-TimeSystems,
Systemcomponents, OperatingSystem services, System Calls.
Operating Systems is the interface between the user and the computer hardware.
devices.
• Application programs : Define the ways in which the system resources are
used to solve the computing problems of the users such as Word processors,
compilers, web browsers, database systems, video games
Dual-Mode Operation:
At the very least, we need two separate modes of operation: user mode and
kernel mode (also called supervisor mode, system mode, or privileged mode). A
bit, called the mode bit, is added to the hardware of the computer to indicate the
current mode: kernel (0) or user (1). With the mode bit, we are able to distinguish
between a task that is executed on behalf of the operating system and one that is
executed on behalf of the user. When the computer system is executing on behalf
of a user application, the system is in user mode. However, when a user
application requests a service from the operating system (via a system call), it
must transition from user to kernel mode to fulfill the request. This is shown in
Figure 1.8.
KernelMode:
• WhenCPUisinkernelmode,thecodebeingexecutedcanaccessanymemor
yaddressand anyhardwareresource.
• Hencekernelmodeisaveryprivilegedandpowerfulmode.
UserMode
• Alluserapplicationsgetexecutedinusermode only.Themodebit= 1.
• WhenCPUisinusermode,theprogramsdon'thavedirectaccesstomemory
andhardwareresources.
• Inuser mode, ifanyprogram crashes, onlythatparticular program is
halted.
• Thatmeansthesystem willbeinasafestate evenifaprogramin
usermodecrashes.
aspects of system operation as well. At system boot time, the hardware starts in
kernel mode. The operating system is then loaded and starts user applications in
user mode. Whenever a trap or interrupt occurs, the hardware switches from user
mode to kernel mode (that is, changes the state of the mode bit to 0). Thus,
whenever the operating system gains control of the computer, it is in kernel
mode. The system always switches to user mode (by setting the mode bit to 1)
before passing control to a user program.
The dual mode of operation provides us with the means for protecting the
operating system from errant users—and errant users from one another. We
accomplish this protection by designating some of the machine instructions that
may cause harm as privileged instructions. The hardware allows privileged
instructions to be executed only in kernel mode. If an attempt is made to execute
a privileged instruction in user mode, the hardware does not execute the
instruction but rather treats it as illegal and traps it to the operating system. The
instruction to switch to user mode is an example of a privileged instruction.
Some other examples include I/O control, timer management, and interrupt
management.
Following are some of the most widely used types of Operating system.
• SimpleBatchSystem
• MultiprogrammingSystem
• TimeSharingSystems
• MultiprocessorSystem
• DistributedOperatingSystem
• ParallelProcessingSystem
• Real-timeOperatingSystem
• PersonalComputerOS
• HandheldSystem
0 3 5 7 11 13 15 17 19 21 23 27
ii. Multiprogramming OS: The processes ready for execution are loaded into the
mainmemory. The OS selects one of these processes and assigns it to the CPU.
Whenever theexecuting process needs to wait for any operation like I/O, the OS
selects another processfrom the job queue and assigns it to the CPU. Latter, when
a partially executed process gets achance to execute, it resumes the execution
from where it stopped previously. This is showninthebelow diagram. This way,
theCPU is kept busyand thethroughput increases.
iii. Time-Sharing Operating Systems: This was introduced in the 1960s when
computerwas too expensive. The solution was to allow many users to use one
computer by providingeach user one time-slot. Each user sit in front of one
terminal and all the terminals are connected to one computer.The time sharing
operating system executes each user task in a given fixed time slot and then
switch to next user task execution. This process is repeated until all tasks are
executed.
divides a single task into many subtasks and thenthesesubtasks can beexecuted
in parallelon different processors.
v. Distributed Operating System: A collection of physically separated
independent computers linked together using the network and works as single
system is called distributed system. All the nodes(computers) in this system
communicate with each other and controlled by the distributed operating system
software.
There are two types of distributed operatingsystems:
a) Client-ServerSystems
b) Peer-to-PeerSystems
Peer-to-Peer Systems: In this model, clients and servers are not distinguished
from oneanother; instead, all nodes (computers) within the system are considered
peers. Each nodemay act as either a client or a server, depending on whether it is
requesting or providing aservice. Peer-to-peer systems offer an advantage over
traditional client-server systems. In aclient-server system, the server is a
bottleneck; but in a peer-to-peer system, all the nodes canacts as a server.
Therefore the load of the server is distributed among all the nodes. This
typeofsystem is also knownas looselycoupled system.
system).
Parallel systems are more difficult to program than computers with a single
4. Multipleinstructionstream,multipledatastream(MIMD).
3. SYSTEMCOMPONENTS
Syeda Sumaiya Afreen pg. 10
CMR Technical Campus
The operating system comprises a set of software components that can be used to
manage interactions with the hardware. Theyare:
Process
management
File Memory
management management
Operating
Systems
• Process synchronization
Main Memory Management: It deals with main memory also called as RAM. Any
programexecution starts only after loading it in to RAM. The following are the main
functions of main memory management.
• Keep track ofwhich parts of memory are currently being used and by
whom.
Secondary storage management: Since main memory (RAM) is volatile and too
small toaccommodate all data and programs permanently, the computer system must
provide secondarystorage to back up main memory. The secondary storage
management component manages thestorage devices, like a hard drive, USB flash
drive (pen drive), DVD drive, or floppy disk drive.The following are the main
functions of secondary storage management.
• Freespacemanagement
• Storageallocation
• Diskscheduling
with creating and manipulating files. The following are the main functions of file
management.
• File and directory creation and deletion.
• It provides device drivers to run the basic I/O devices such as keyboard
and mouse.
• It providesecuritymechanisms
• Itprovidecontrolaccess mechanism
4. OPERATINGSYSTEMFUNCTIONS /SERVICES/TASKS
5. SYSTEMCALLS
A system call is a programmatic interface between user process and OS kernel.
It isamechanism in whichuser program make a request to get service form
kernel.System call provides the services to the user programs via Application
Program Interface(API).The common APIs available for most operating systems or
virtual machine sare:
API OperatingSystem
Win32 API Windows
POSIXAPI Unix,Linux, MacOS X
Java API JavaVirtualMachine(JVM)
Let's first use an example to illustrate how system calls are used: writing a simple
program to
read data from one file and copy them to another file.
In order to do this work first we need to take the two file names as input.
The total operation is expressed below. Though it is a simple task itself it needs so
Syeda Sumaiya Afreen pg. 15
CMR Technical Campus
Before the system call enters into kernel mode, the user application pauses and the
control istransferred tothe kernelby setting mode bit = 0. If the request is allowed,
the kernel processesthe request, for example creating or deleting a file. When the
operation is complete, the kernelpasses the output back to the application and set the
mode bit =1. The application receives
the output from the kernel as parameter value.Once the input is received, the
application resumes the process.The interaction between user mode and kernel mode
is shown in the below figure.
The run-time support system (a set of functions built into libraries included
with a compiler) for most programming languages provides a system-call interface
that serves as the link to system calls made available by the operating system. The
system-call interface intercepts function calls in the API and invokes the necessary
system call within the operating system. Typically, a number is associated with each
system call, and the system-call interface maintains a table indexed according to
these numbers. The system call interface then invokes the intended system call in
the operating system kernel and returns the status of the system call and any return
values.
The relationship between an API, the system-call interface, and the operating
system is shown in Figure 2.3, which illustrates how the operating system handles a
user application invoking the open() system call.
For example, when a user application needs a file, a system call called open() is
generated. Theuser application passes the parameters such as file name, path name
to the kernel by changing themode bit to 0. If the requested file exists (request is
valid), the file is opened by the kernel andchanges the mode bit to 1. Later, the
Syeda Sumaiya Afreen pg. 17
CMR Technical Campus
address of the opened file is passed back as a return value totheuser application. This
is shown in thebelow figure.
Generally user application executes in user mode and when it needs support from
OS, a systemcall is generated.When an application makes a system call, it passes the
required parameters to the kernel. The three general methods for passing parameters
to the OS kernel are:
1. Parameters can be passed in registers.
2. When there are more parameters than number of registers, parameters can be
system.
Generally,system calls are made by the user level programs in the following
situations:
The system calls can be categorized broadly into five types. They are:
iv. InformationMaintenance:Thesesystemcallshandleinformationanditstransfe
rbetween the operating system and the user program. Some of the important
system callunderthis categoryare:
GetCurrentProcessID( ): It is used to get the curren texecuting
process ID.
SetTimer(): It is used to create a timer with the specified time
out value.
Sleep():It is used to make a process to sleep,which places it into an inactive
state.
6.OPERATINGSYSTEMSTRUCTURE
i. Simple Structure: Operating systems such as MS-DOS and the original UNIX
did nothave well-defined structures. Frequently, such operating systems started
as small, simple, and limited systems and then grew beyond their original scope.
MS-DOS is an example ofsuch a system. It was originally designed and
implemented by a few people who had no ideathat it would become so popular.
It was written to provide the most functionality in the least space,so it was not
designed carefully. InMS-DOS, the interfaces and levels of functionality are not
well separated. So, errors in applications could cause the whole systemtocrash.
ii. Layered Approach: The operating system is divided into a number of layers
(levels),each built on top of lower layers. The bottom layer (layer 0), is the
hardware; the highest(layer N) is the user interface. The lower layer provides
service to its next higher layer. Themain advantage of the layered approach is
simplicity of construction and debugging.It iseasier to create, maintain and
update the operating system. Change in one layer does notaffecttherest of
thelayers.
• It requires careful planning for designing the layers as higher layers use the
functionalities of only the lower layers.
iii. Microkernel: This method structures the operating system by removing all non-
essential components from the kernel and implementing them as system or user-
level programs. The result is a smaller kernel. Kernel is the core part of an OS
which manages system resources.It also acts like a bridge between application
and hardware of the computer. The client programand service neve interact
directly. Rather,they communicate indirectly by exchanging messages with the
microkernel. All new services are added to user space and as a result there is no
need to modify the kernel.As most of the services are running as user Processes
rather than kernel processes, the microkernel provides more security and
reliability.
messages messages
microkernel
hardware
iv. Modules: The best methodology for operating system design involves using
modular kernel. In this,the kernel has a set of core components and additional
services are dynamically linked either during boot time or during run time.It is
used in modern implementations of UNIX, such as Solaris, Linux, and Mac OS
X. For example, the Solarisoperating system structure is organized around a core
kernel with seven types of loadable kernel modules:
Even though this structure resembles a layered system, it is more flexible than a
layeredsystem because any module can call any other module. Furthermore, this
approach is like the micro kernel approach but it is more efficient, because
modules do not need to invoke message passing in order to communicate.
Advantages −
• Efficient
• Easy to maintained
• Easy to debug and update
Disadvantages −