Os Unit 1
Os Unit 1
• System calls provide a means for user or application programs to call upon the services of
the operating system.
• Generally written in C or C++, although some are written in assembly for optimal
performance.
Definition
The interface between a process and an operating system is provided by system calls. In
general, system calls are available as assembly language instructions. To call upon the services
of the operating system we use system calls.
• Parameters are generally passed to system calls via registers, or less commonly, by values
pushed onto the stack. Large blocks of data are generally accessed indirectly, through a
memory address passed in a register or on the stack, as shown in Figure
5. Communication
• Communication system calls create/delete communication connection, send/receive
messages, transfer status information, and attach/detach remote devices.
• The message passing model must support calls to:
• Identify a remote process and/or host with which to communicate.
• Establish a connection between the two processes.
• Open and close the connection as needed.
• Transmit messages along the connection.
• Wait for incoming messages, in either a blocking or non-blocking state.
• Delete the connection when no longer needed.
• The shared memory model must support calls to:
• Create and access memory that is shared amongst processes ( and threads. )
• Provide locking mechanisms restricting simultaneous access.
• Free up shared memory and/or dynamically allocate it as needed.
• Message passing is simpler and easier, ( particularly for inter-computer communications ),
and is generally appropriate for small amounts of data.
• Shared memory is faster, and is generally the better approach where large amounts
of data are to be shared, ( particularly when most processes are reading the data rather than
writing it, or at least when only one or a small number of processes need to change any given
data item. )
6. Protection
• Protection provides mechanisms for controlling which users / processes have access to
which system resources.
• System calls allow the access mechanisms to be adjusted as needed, and for non- privileged
users to be granted elevated access permissions under carefully controlled temporary
circumstances.
• Once only of concern on multi-user systems, protection is now important on all systems,
in the age of ubiquitous network connectivity.
SYSTEM PROGRAMS
• System programs provide OS functionality through separate applications, which are not
part of the kernel or command interpreters.
• They are also known as system utilities or system applications.
• Most systems also ship with useful applications such as calculators and simple editors, (
e.g. Notepad ). Some debate arises as to the border between system and non-system
applications.
System programs may be divided into these categories:
1. File management - programs to create, delete, copy, rename, print, list, and
generally manipulate files and directories.
2. Status information - Utilities to check on the date, time, number of users, processes
running, data logging, etc. System registries are used to store and recall
configuration information for particular applications.
3. File modification - e.g. text editors and other tools which can change file contents.
4. Programming-language support - E.g. Compilers, linkers, debuggers, profilers,
assemblers, library archive management, interpreters for common languages, and
support for make.
5. Program loading and execution - loaders, dynamic loaders, overlay loaders, etc., as
well as interactive debuggers.
6. Communications - Programs for providing connectivity between processes and
users, including mail, web browsers, remote logins, file transfers, and remote
command execution.
7. Background services - System daemons are commonly started when the system is
booted and run for as long as the system is running, handling necessary services.
Examples include network daemons, print servers, process schedulers, and system
error monitoring services.
OPERATING-SYSTEM GENERATION
OS may be designed and built for a specific HW configuration at a specific site, but
more commonly they are designed with a number of variable parameters and components,
which are then configured for a particular operating environment.
• Systems sometimes need to be re-configured after the initial installation, to add additional
resources, capabilities, or to tune performance, logging, or security.
Information that is needed to configure an OS include:
• What CPU(s) are installed on the system, and what optional characteristics does each have?
• How much RAM is installed? ( This may be determined automatically, either at install or
boot time. )
• What devices are present? The OS needs to determine which device drivers to include,
as well as some device-specific characteristics and parameters.
• What OS options are desired, and what values to set for particular OS parameters.
The latter may include the size of the open file table, the number of buffers to use, process
scheduling (priority) parameters, disk scheduling algorithms, number of slots in the process
table, etc.
2 Options
• At one extreme the OS source code can be edited, re-compiled, and linked into a new
kernel.
• At the other extreme a system configuration may be entirely defined by table data, in which
case the "rebuilding" of the system merely requires editing data tables.
• Once a system has been regenerated, it is usually required to reboot the system to activate
the new kernel. Because there are possibilities for errors, most systems provide some
mechanism for booting to older or alternate kernels.
System Boot
The procedure of starting a computer by loading the kernel is known as booting the system.
A small piece of code known as the bootstrap program or bootstrap loader locates the
kernel, loads it into main memory, and starts its execution.
First a simple bootstrap loader fetches a more complex boot program from disk
A complex boot program loads the OS
The bootstrap program can perform a variety of tasks. Usually, one task is to run
diagnostics to determine the state of the machine.
It can also initialize all aspects of the system, from CPU registers to device controllers
and the contents of main memory and then it starts the Operating system.
All forms of ROM are also known as firmware, since their characteristics fall
somewhere between those of hardware and those of software.
A problem with firmware in general is that executing code there is slower than
executing code in RAM.
Some systems store the operating system in firmware and copy it to RAM for fast
execution.
A final issue with firmware is that it is relatively expensive, so usually only small
amounts are available.
For large operating systems the bootstrap loader is stored in firmware, and the
operating system is on disk.
The Bootstrap program has a piece of code that can read a single block at a fixed
location from disk into memory and execute the code from that Boot block.
The program stored in the boot block may be sophisticated enough to load the entire
operating system into memory and begin its execution.
A disk that has a Boot partition is called as a Boot Disk.
GRUB is an example of an open-source bootstrap program for Linux systems.
OPERATING SYSTEM STRUCTURE:
The operating systems are large and complex. A common approach is to partition
the task into small components, or modules, rather than have one monolithic system.
The structure of an operating system can be defined the following structures.
• Simple structure
• Layered approach
• Microkernels
• Modules
• Hybrid systems
Simple structure:
The Simple structured operating systems do not have a well-defined structure.
These systems will be simple, small and limited systems.
Example: MS-DOS.
• In MS-DOS, the interfaces and levels of functionality are not well separated.
• In MS-DOS application programs are able to access the basic I/O routines. This causes
the entire systems to be crashed when user programs fail.
Example: Traditional UNIX OS
It consists of two separable parts: the kernel and the system programs.
• The kernel is further separated into a series of interfaces and device drivers
• The kernel provides the file system, CPU scheduling, memory management, and other
operating-system functions through system calls.
Layered approach:
• A system can be made modular in many ways. One method is the layered approach,
in which the operating system is broken into a number of layers (levels). The bottom
layer (layer 0) is the hardware; the highest layer is the user interface.
• An operating-system layer is an implementation of an abstract object made up of data
and the operations that can manipulate those data.
• The main advantage of the layered approach is simplicity of construction and
debugging. The layers are selected so that each uses functions (operations) and
services of only lower-level layers.
• Each layer is implemented only with operations provided by lower-level layers. A layer
does not need to know how these operations are implemented; it needs to know only
what these operations do.
• The major difficulty with the layered approach involves appropriately defining the
various layers because a layer can use only lower-level layers.
• A problem with layered implementations is that they tend to be less efficient than
other types.
Fig : Layered Approach
Microkernels:
• In the mid-1980s, researchers at Carnegie Mellon University developed an operating
system called Mach that modularized the kernel using the microkernel approach.
• This method structures the operating system by removing all nonessential
components from the kernel and implementing them as system and user-level
programs.
• Microkernel provide minimal process and memory management, in addition to a
communication facility.
• The main function of the microkernel is to provide communication between the client
program and the various services that are also running in user space.
• The client program and service never interact directly. Rather, they communicate
indirectly by exchanging messages with the microkernel.
• One benefit of the microkernel approach is that it makes extending the operating
system easier. All new services are added to user space and consequently do not
require modification of the kernel.
• The performance of microkernel can suffer due to increased system-function
overhead.
Fig : Architecture of typical microkernel
Modules:
• The best current methodology for operating-system design involves using loadable
kernel modules
• The kernel has a set of core components and links in additional services via modules,
either at boot time or during run time.
• The kernel provides core services while other services are implemented dynamically,
as the kernel is running.
• Linking services dynamically is more comfortable than adding new features directly to
the kernel, which would require recompiling the kernel every time a change was made.
Example: Solaris OS
The Solaris operating system structure is organized around a core kernel with seven types of
loadable kernel modules:
• Scheduling classes
• File systems
• Loadable system calls
• Executable formats
• STREAMS modules
• Miscellaneous
• Device and bus drivers
Hybrid Systems:
• The Operating System combines different structures, resulting in hybrid systems that
address performance, security, and usability issues.
• They are monolithic, because having the operating system in a single address space
provides very efficient performance.
• However, they are also modular, so that new functionality can be dynamically added
to the kernel.
Example: Linux and Solaris are monolithic (simple) and also modular, IOS.
OPERATING-SYSTEM OPERATIONS
Interrupt-driven nature of modern OS requires that erroneous processes not be able to
disturb anything else.
Dual-Mode and Multimode Operation
• User mode when executing harmless code in user applications
• Kernel mode ( a.k.a. system mode, supervisor mode, privileged mode ) when executing
potentially dangerous code in the system kernel.
• Certain machine instructions ( privileged instructions ) can only be executed in kernel mode.
• Kernel mode can only be entered by making system calls. User code cannot flip the mode
switch.
• Modern computers support dual-mode operation in hardware, and therefore most modern
OSes support dual-mode operation.
Fig : Transition from user to kernel mode
• The concept of modes can be extended beyond two, requiring more than a single mode bit
• CPUs that support virtualization use one of these extra bits to indicate when the virtual
machine manager, VMM, is in control of the system. The VMM has more privileges than
ordinary user programs, but not so many as the full kernel.
• System calls are typically implemented in the form of software interrupts, which causes
the hardware's interrupt handler to transfer control over to an appropriate interrupt handler,
which is part of the operating system, switching the mode bit to kernel mode in the process.
• The interrupt handler checks exactly which interrupt was generated, checks additional
parameters ( generally passed through registers ) if appropriate, and then calls the
appropriate kernel service routine to handle the service requested by the system call.
• User programs' attempts to execute illegal instructions ( privileged or non- existent
instructions ), or to access forbidden memory areas, also generate software interrupts, which
are trapped by the interrupt handler and control is transferred to the OS, which issues an
appropriate error message, possibly dumps data to a log ( core ) file for later analysis, and
then terminates the offending program.
Thuadl:
guets State
7 when a chauges
The tatus
Raeut.
Rent to
llolatd.
Wating o the peLessor to be
Diaqian e pous Stat
New
lotmited
~nteanupt
Ready
Uset
4t detemni
hirs.
hs t Pautss hos to e Rlutd
Aich
alhocati tune. bur
4t ols
n uee 4t also $torocl in tte pouLs
Monagement fugoTmettien
focs Sceduling:
The
olees.
(etest Suiteh:
(asLunisg)
to onethel ppuetsstne
that the Conte t, s
intoougt at
Swtth It is calad Conat
The
en memy
poceses
may
ystm lal.
ddun
ERh the teese hew
Pido
init
page
id pidg
pont.
chiled Can sahe Pogiam ard data
patent
’ he chiled can hta
hot a new
tan
Prouslenmaion
p cess enated conen it finishs
He
POret
+a2minat chie in
hidel in heye onoitLons
lonqn quid
ohen t e paent oinati ) u the chiloen
blo lt w Þe tainatd
io the
Aystm roy e then inolepuront fhotus o
to-opuotug prouss.
Thons ae
a task nto
med
Unmec by an assinelen, The
tenpunty
that Car the
Consumel
) thot s he
USnnel
mt e
mlsndesl
mnit ie nthe
the tu
lvay pooolen Wawt
to allbw
aton wyo
sittheut Ahasin th
Suncmye the
whee
a
be
charg
is ou'ysict
charg
thy
Caun be imted in many
woys. Fhes ewelal met for
onialhy Limplnintngod) neae()
opuotions, lire :
) D'net (oa) idit Conmbicahon
AtPmati
Tuae
)dyoomigotien
)Puttang.
Noming
7 foeyses that wart to Cioncate
boea way to s
Uomnmctn
.
rallbohas
y viwy
Conmunicohon: ni'uot with
to
endel he
ep; the thehons rde The
othe
oheyt none mt ps accei
poun.psOs,
these Rash
te as
ienink
toukes Plaue
detwen to lsteuhcalionComnnm
may
tonwpeoling
oe to ine Raheath
inee ouitbenet mnoeeo with
a be may
Rah Bstiween
the
Pod
malbos
A.
l phawd &bhee a
2 fuoeys may be
ynchueg yrhaonsus
bloiking.
the message is g0ceitd ey ae
the mael.
anyrhwneus
fnctin, it wont hait
Butonng: wtnE
whethn commniatisu is ou'atfon )
incuteet, mecsngl Lhavgeat
addes ond
fovt
hest
Ct4b-sb-5. 20)
Sptket
l4b:sb 5.20: |b2b wes Swel
forrno (751:2524-8
ocleet
|6)-25-19-9
’ T host nd gewt msg boy that
the gos
the oWer commicate iwith the
ot
Tha I addey ceuists c oun foss.
ppu teolne Coul
Calling puocuuou win loata ën
bystuncae
Pipes: 1
As
igt ho mou comauol