0% found this document useful (0 votes)
99 views35 pages

Introduction To Operating Systems, System Structures

The document discusses the introduction to operating systems and system structures. It provides definitions of an operating system, describing what they do and their main components. The document outlines computer system organization including CPU, memory, I/O devices and storage hierarchy. It also discusses operating system architecture in mainframe systems and how early computers were operated through job submission to a computer operator using punched cards.

Uploaded by

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

Introduction To Operating Systems, System Structures

The document discusses the introduction to operating systems and system structures. It provides definitions of an operating system, describing what they do and their main components. The document outlines computer system organization including CPU, memory, I/O devices and storage hierarchy. It also discusses operating system architecture in mainframe systems and how early computers were operated through job submission to a computer operator using punched cards.

Uploaded by

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

GLOBAL ACADEMY OF TECHNOLOGY

Department of Computer Science &Engineering


(Accredited by NBA 2019-2022)

OPERATING SYSTEMS
(18CS43)

MODULE 1

INTRODUCTION TO OPERATING SYSTEMS, SYSTEM STRUCTURES:

What operating systems do; Computer System organization; Computer System


architecture; Operating System structure; Operating System operations; Process
management; Memory management; Storage management; Protection and security;
Distributed system; Special-purpose systems; Computing environments. Operating
System Services; User -Operating System interface; System calls; Types of system
calls; System programs; Operating System design and implementation; Operating
System structure; Virtual machines; Operating System generation; System boot.
Process concept; Process scheduling; Operations on processes; Inter-process
communication. 10 Hours

TEXT BOOK:
1. Operating System Principles –Abraham Silberschatz, Peter Baer Galvin,
GregGagne, 7th edition, Wiley-India, 2009

REFERENCE BOOKS:
1. Operating Systems: A Concept Based Approach –D.M Dhamdheere, 2ndEdition,
Tata McGraw-Hill, 2002.
2. Operating Systems –P.C.P. Bhatt, 2ndEdition, PHI, 2006.
3. Operating Systems –Harvey M Deital, 3rdEdition, Addison Wesley, 1990.
OPERATING SYSTEMS – 18CS43 2021
INTRODUCTION TO OPERATING SYSTEMS, STRUCTURES

WHAT OPERATING SYSTEM DO?


• An OS is a program which acts as an intermediary between the user of the computer
& the computer hardware.
• It provides a basis for application program.
• The purpose of an OS is to provide a environment in which the user can
execute the program in a convenient & efficient manner.
• OS is an important part of almost every computer systems.
• A computer system can be divided into four components

The OS

The Hardware

The application Program

The user
• The Hardware consists of memory, CPU, ALU, I/O devices, peripherals devices &
storage devices.
• The application program consists of word processors, spread sheets, compilers & web
browsers.
• The OS controls & co-ordinates the use of hardware among various application
program for various users.

Figure: Abstract view of the components of a computer system.

Views of Operating System:


The operating system can be viewed in two ways. They are:
a) User view
b) System view
User View:
The user view of the computer depends on the interface used.
Some users may use
1) PC’s.
i) In this the system is designed so that only one user can utilize the resources
ii) The attention is mainly on performances and not on the resource utilization.
2) A terminal connected to a mainframe or minicomputers.
3) The same computer through other terminals.
i) These users may share resources and exchange information.
ii) In this case the OS is designed to maximize resource utilization-so that all
available CPU time, memory & I/O are used efficiently.
4) Workstations
i) Connected to the networks of other workstation and servers.

Shruthi.P, Dept CSE, GAT Page 2


OPERATING SYSTEMS - 18CS43 2021
ii) In this case OS is designed to compromise between individual visibility &
resource utilization.

System View:
System has many resources that may be used to solve a problem.
• The OS acts as a manager of these resources (resource allocator).
• The OS must decide how to allocate these resources to programs and the users.
• The OS need to control various I/O devices & user programs.
• An OS is a control program used to manage the execution of user program to
prevent errors and improper use of the computer.
Operating System Definition
• OS is a resource allocator that manages all resources.
• Decides between conflicting requests for efficient and fair resource.
• OS act as a control program. It controls execution of programs to prevent errors and
improper use of the computer.

Computer System Organization


Computer-system operation: One or more CPUs, device controllers connect through common
bus providing access to shared memory. Concurrent execution of CPUs and devices
competing for memory cycles.

Figure: A Modern Computer System

Computer-System Operation
• I/O devices and the CPU can execute concurrently.
• Each device controller is in charge of a particular device type.
• Each device controller has a local buffer.
• CPU moves data from/to main memory to/from local buffers.
• Device controller informs CPU that it has finished its operation by causing an
interrupt.
• The occurrence of an event is usually signalled by an interrupt from either hardware
or the software. Hardware may trigger an interrupt by executing a special operation
called a system call (also called as a monitor call).
Common Functions of Interrupts:
An operating system is interrupt driven. Interrupt transfers control to the interrupt
serviceroutine generally, through the interrupt vector, which contains the addresses of all
theservice routines.
Interrupt Handling:
• The operating system preserves the state of the CPU by storing registers
and the program counter.
• Determines which type of interrupt has occurred.
Interrupt Timeline:

Shruthi.P, Dept CSE, GAT Page 3


OPERATING SYSTEMS - 18CS43 2021

Figure: Interrupt time line for a single process doing output.

Bootstrap program: it is loaded at power-up or reboot.


• Typically stored in ROM or EPROM, generally known as firmware.
• Initializes all aspects of system.
• Loads operating system kernel and starts execution.
Direct Memory Access Structure
• Used for high-speed I/O devices able to transmit information at close to memory
speeds.
• Device controller transfers blocks of data from buffer storage directly
to main memory without CPU intervention.
• Only one interrupt is generated per block, rather than the one interrupt
per byte.

Storage Structure
• Main memory – only large storage media that the CPU can access directly.
• Secondary storage – extension of main memory that provides large non-
volatile storage capacity.
• Magnetic disks – rigid metal or glass platters covered with magnetic
recording material.
• Disk surface is logically divided into tracks, which are subdivided into sectors. The
disk controller determines the logical interaction between the device and the computer.

Storage Hierarchy
• Storage systems organized in hierarchy
• Speed
• Cost
• Volatility

Figure: Storage- device hierarchy

Caching –copying information into faster storage system; main memory can be viewedas
a last cache for secondary storage.

Shruthi.P, Dept CSE, GAT Page 4


OPERATING SYSTEMS - 18CS43 2021
• Important principle, performed at many levels in a computer (in hardware,
operating system, software).
• Information in use copied from slower to faster storage temporarily.
• Faster storage (cache) checked first to determine if information is there
if it is, information used directly from the cache (fast).
• If not, data is copied to cache and used.
The OS must support the following tasks:
• Provide the facility to create, modification of programs & data files using on
editors.
• Access to compilers for translating the user program from high level language to
machine language.
• Provide a loader program to move the compiled program code to computers
memory for execution.
• Provides routines that handle the details of I/O programming.

OPERATING SYSTEM ARCHITECTURE


Mainframe System:
Mainframe systems are mainly used for scientific & commercial applications.
An OS may process its workload serially where the computer runs only one application or
concurrently where computer runs many applications.
• Early computers where physically large machines.
• The common I/P devices are card readers & tape drives.
• The common O/P devices are line printers, tape drives & card punches.
• The users do not interact directly with computers but we use to prepare a job
with the program, data & some control information & submit it to the
computer operator.
• The job was mainly in the form punched cards.
• At later time the O/P appeared and it consisted of result along with dump of
memory and register content for debugging.
• The OS of these computers was very simple.
• Its major task was to transfer control from one job to the next.
• The OS was always resident in the memory.
• The processing of job was very slow.

Batch Systems:
• To improve the processing speed operators batched together the jobs with similar
needs and processed it through the computers. This is called Batch Systems.
• In batch systems the CPU may be idle for some time because the speed of the
mechanical devices slower compared to the electronic devices. Later
improvement in technology and introduction of disks resulted in faster I/O
devices. The introduction of disks allowed the OS to store all the jobs on the
disk.
• The OS could perform the scheduling to use the resources and perform the
task efficiently.
Disadvantages of Batch Systems:
• Turnaround time can be large from user.
• Difficult to debug the program.
• A job can enter into infinite loop.
• A job could corrupt the monitor.
• Due to lack of protection scheme, one job may affect the pending jobs.
Multi programmed System:
Shruthi.P, Dept CSE, GAT Page 5
OPERATING SYSTEMS - 18CS43 2021
• If there are two or more programs in the memory at the same time sharing the
processor, this is referred as multi programmed OS.
• It increases the CPU utilization by organizing the jobs so that the CPU will always
have one job to execute.
• Jobs entering the systems are kept in memory.
• OS picks the job from memory & it executes it.
• Having several jobs in the memory at the same time requires some form of memory
management.
• Multi programmed systems monitors the state of all active program and system
resources and ensures that CPU is never idle until there are no jobs.
• While executing a particular job, if the job has to wait for any task like I/O
operation to be complete then the CPU will switch to some other jobs and starts
executing it and when the first job finishes waiting the CPU will switch back to
that.
• This will keep the CPU & I/O utilization busy.
The following figure shows the memory layout of multi programmed OS:

Figure: Memory layout for a multiprogramming system

Time sharing Systems:


• Time sharing system or multi tasking is logical extension of multi
programming systems.
• The CPU executes multiple jobs by switching between them but the switching
occurs so frequently that user can interact with each program while it is
running.
• An interactive & hands on system provides direct communication between the
user and the system.
• The user can give the instruction to the OS or program directly through key board
or mouse and waits for immediate results.
• A time shared system allows multiple users to use the computer simultaneously.
• Since each action or commands are short in time shared systems only a small
CPU time will be available for each of the user.
• A time shared systems uses CPU scheduling and multi programming to provide
each user a small portion of time shared computers.
• When a process executes it will be executing for a short time before it finishes or need
to perform I/O.
• I/O is interactive i.e. O/P is to a display for the user & the I/O is from a keyboard,
mouse etc. Since it has to maintain several jobs at a time, system should have
memory management & protection.

Shruthi.P, Dept CSE, GAT Page 6


OPERATING SYSTEMS - 18CS43 2021
• Time sharing systems are complex than the multi programmed systems. Since several
jobs are kept in memory they need memory management and protection.
• To obtain less response time jobs are swapped in and out of main memory to
disk. This can be achieved by using a technique called virtual memory that
allows for the execution of job i.e. not complete in memory.
• It supports concurrent execution, job synchronization & communication.
Operating System operations:
Dual-mode operation:

Figure: Transition from user to kernel mode.

• Dual-mode operation allows OS to protect itself and other system components.


• User mode and kernel mode.
• Mode bit is provided by hardware. When mode bit=1 it is in user mode and when
mode bit=0 it is in kernel mode.
• Provides ability to distinguish when system is running user code or kernel code.
• Some instructions designated as privileged, only executable in kernel mode.
• System call changes mode to kernel, return from call resets it to user.

DESKTOP SYSTEMS:
• Pc’s appeared in 1970’s and during this they lacked the feature needed to protect
an operating system from user program and they even lack neither multiuser nor
multi tasking.
• The goals of those OS changed later with the time and new systems include
Microsoft Windows & Apple Macintosh.
• The Apple Macintosh OS ported to more advanced hardware & includes new
features like virtual memory & multi tasking.
• Micro computers are developed for single user in 1970’s &they can
accommodate software with large capacity & greater speeds.
• MS-DOS is an example for micro computer OS & are used by commercial,
educational, government enterprises.

Multi Processor Systems:


• Multi processor systems include more than one processor in close communication.
• They share computer bus, the clock, m/y & peripheral devices.
Two processes can run in parallel.
o Multi processor systems are of two types
• Symmetric Multi processors ( SMP)
o Each processors runs an identical copy of OS o
They communicate with one another as needed. o
All the CPU shares the common memory.
o All processors are peers i.e. no master slaverelationship
exists between processors.
o Each processor concurrently runs a copy of OS.

Shruthi.P, Dept CSE, GAT Page 7


OPERATING SYSTEMS - 18CS43 2021
• Asymmetric Multi processors.(ASMP)
o Each processor is assigned a specific
task. o It uses a master slave relationship.
o A master processor controls the system.
o The master processors schedules and allocates work to slave processors.
The differences between symmetric & asymmetric multi processing may be result of
either H/w or S/w.
Special H/w can differentiate the multiple processors or the S/w can be written to allow
only master & multiple slaves.
Advantages of Multi Processor Systems:
1. Increased Throughput: By increasing the Number of processors we can get
morework done in less time. When multiple process co-operate on task, a certain
amount of overhead is incurred in keeping all parts working correctly.
2. Economy of Scale: Multi processor system can save more money than
multiplesingle processors, since they share peripherals, mass storage & power
supplies. If many programs operate on same data, they will be stored on one disk
& all processors can share them instead of maintaining data on several systems.
3. Increased Reliability: If a program is distributed properly on several
processors,then the failure of one processor will not halt the system but it only
slows down.

OPERATING SYSTEM STRUCTURES


PROCESS CONTROL & JOB CONTROL:
• A system call can be used to terminate the program either normally or
abnormally.
• Reasons for abnormal termination are dump of m/y, error message generated
etc.
• Debugger is mainly used to determine problem of the dump & returns back the
dump to the OS.
• In normal or abnormal situations the OS must transfer the control to the command
interpreter system.
• In batch system the command interpreter terminates the execution of job &
continues with the next job.
• Some systems use control cards to indicate the special recovery action to be taken
in case of errors.
• Normal & abnormal termination can be combined at some errors level.
• Error level is defined before & he command interpreter uses this error level to
determine next action automatically.

MS-DOS:
• MS-DOS is an example of single tasking system.
• It has command interpreter system i.e. invoked when the computer is started.
• To run a program MS-DOS uses simple method.
• It does not create a process when one process is running MS-DOS the program into
memory & gives the program as much as possible.
• It lacks the general multitasking capabilities.

Shruthi.P, Dept CSE, GAT Page 8


OPERATING SYSTEMS - 18CS43 2021

Figure: MS-DOS execution (a)At system startup (b) Running a program


BSD:
Free BSD is an example of multitasking system. In free BSD the command interpreter may
continue running while other program is executing. FORK is used to create new process.

Figure: FreeBSD running multiple programs.

OPERATING SYSTEM OPERATIONS


Modern OS supports all system components. The system components are:
• Process Management.
• Main Memory Management.
• File Management.
• Secondary Storage Management.
• I/O System management.
• Networking.
• Protection System.
• Command Interpreter System.

PROCESS MANAGEMENT:
• A process is a program in execution.
• A process abstraction is a fundamental OS mechanism for the
management of concurrent program execution.
• The OS responds by creating process.
• Process requires certain resources like CPU time, Memory, I/O devices. These
resources are allocated to the process when it created or while it is running.
• When process terminates the process reclaims all the reusable resources.
• A program by itself is not a process but is a passive entity
The OS is responsible for the following activities of the process management:
• Creating & destroying of the user & system process.
• Allocating H/w resources among the processes.
• Controlling the progress of the process.
• Provides mechanism for process communication.
Shruthi.P, Dept CSE, GAT Page 9
OPERATING SYSTEMS - 18CS43 2021
• Provides mechanism for deadlock handling.

MEMORY MANAGEMENT:
• Main Memory is the centre to the operation of the modern computer.
• Main Memory is the array of bytes ranging from hundreds of thousands to
billions.
• The I/O operation reads and writes data in main Memory.
• The main Memory is generally a large storage device in which a CPU can address
& access directly.
• When a program is to be executed it must be loaded into memory& mapped to
absolute address.
• When it is executing it access the data & instruction from Memory by generating
absolute address.
• When the program terminates all available Memory will be returned back.
The OS is responsible for the following activities:
• Keeping track of which part of the Memory is used & by whom.
• Deciding which process are to be loaded into Memory.
• Allocating & de allocating Memory space as needed.

FILE MANAGEMENT:
• File management is one of the most visible component of an OS.
• Computer stores data on different types of physical media like Magnetic Disks,
Magnetic tapes, optical disks etc.
• For convenient use of the computer system the OS provides uniform logical view of
information storage.
• The OS maps file on to physical media & access these files via storage devices.
• A file is logical collection of information.
• File consists of both program & data. Data files may be numeric, alphabets or
alphanumeric.
• Files can be organized into directories.
The OS is responsible for the following activities:
• Creating & deleting of files.
• Creating & deleting directories.
• Supporting primitives for manipulating files & directories.
• Mapping files onto secondary storage.
• Backing up files on stable storage media.

STORAGE MANAGEMENT:
• Is a mechanism where the computer system may store information in a way that it
can be retrieved later.
• They are used to store both data & programs.
• Since the size of the M/y is small & volatile Secondary storage devices is used.
• Magnetic disk is central importance of computer system.
The OS is responsible for the following activities:
• Free space management.
• Storage allocation.
• Disk scheduling: The entire speed of computer system depends on the speed of the
disk sub system.

I/O SYSTEM MANAGEMENT:

Shruthi.P, Dept CSE, GAT Page 10


OPERATING SYSTEMS - 18CS43 2021
• Each I/O device has a device handler that resides in separate process associated with
that device.
• The I/O management consists of Memory management components that
include buffering, caching & spooling.
• General device-driver interface.
• Drivers for specific H/w device.

Networking:
• Networking enables users to share resources & speed up computations.
• The process communicates with one another through various communication lines
like high speed buses or N/w.
• Following parameters are considered while designing the N/w,
o Topology of N/w.
o Type of N/w.
o Physical media.
o Communication protocol.
o Routing algorithms.

PROTECTION AND SECURITY:


• Modern computer system supports many users & allows the concurrent execution
of multiple processes organization rely on computers to store information.
• It necessary that the information & devices must be protected from unauthorized
users or processors.
• The protection is a mechanism for controlling the access of program, processes
or users to the resources defined by a computer system.
• Protection mechanisms are implemented in OS to support various security policies.
• The goal of security system is to authenticate their access to any object.
• Protection can improve reliability by detecting latent errors at the interface B/w
component sub system.
• Protection domains are extensions of H/w supervisor mode ability.

DISTRIBUTED SYSTEMS
• A distributed system is one in which H/w or S/w components located at
the networked computers communicate & co ordinate their actions only
by passing messages.
• A distributed systems looks to its user like an ordinary OS but runs on multiple,
Independent CPU’s.
• Distributed systems depends on networking for their functionality which allows
for communication so that distributed systems are able to share computational
tasks and provides rich set of features to users.
• N/w may vary by the protocols used, distance between nodes & transport media.
o Protocols: TCP/IP, ATM etc.
o Network: LAN, MAN, WAN etc.
o Transport Media: copper wires, optical fibres & wireless transmissions
Advantages of Distributed Systems:
1. Resource sharing.
2. Higher reliability.
3. Better price performance ratio.
4. Shorter response time.
5. Higher throughput.
6. Incremental growth.

Shruthi.P, Dept CSE, GAT Page 11


OPERATING SYSTEMS - 18CS43 2021

Client-Server Systems:
The centralized system today acts as server program to satisfy the requests of client. Server
system can be classified as follows
Computer-Server Systems: Provides an interface to which client can send requests
toperform some actions, in response to which they execute the action and send back result to
the client.
File-Server Systems: Provides a file system interface where clients can create, update,
read& delete files.

Peer-to-Peer Systems:
• PC’s are introduced in 1970’s they are considered as standalone computers.
• With wide spread use of internet PC’s were connected to computer networks.
• With the introduction of the web in mid 1990’s N/w connectivity became an
essential component of a computer system.
• All modern PC’s & workstation can run a web.
• Os also includes system software that enables the computer to access the web.
• The processor can communicate with one another through various
communication lines like high speed buses or telephones lines.

SPECIAL-PURPOSE SYSTEMS:
Clustered Systems:
• Like parallel systems the clustered systems will have multiple CPU but they are
composed of two or more individual system coupled together.
• Clustered systems share storage & closely linked via LAN N/w.
• Clustering is usually done to provide high availability.
• Clustered systems are integrated with H/w & S/w.
o H/w clusters means sharing of high performance disk.
o S/w clusters are in the form of unified control of a computer system in a
cluster.
• A layer of S/w cluster runs on the cluster nodes. Each node can monitor one or more
of the others.
• If the monitored Machine fails the monitoring Machine take ownership of its
storage and restart the applications that were running on failed Machine.
Clustered systems can be categorized into two groups
1. Asymmetric clustering
• One Machine is in hot standby mode while others are running the application.
• The hot standby Machine does nothing but it monitors the active server.
• If the server fails the hot standby Machine becomes the active server.
2. Symmetric clustering
• Two or more hosts are running the Application & they monitor each other.
• This mode is more efficient since it uses all the available H/w.

Real-Time Systems
• Real time system is one which were originally used to control autonomous systems
like satellites, robots, hydroelectric dams etc.
• Real time system is one that must react to I/p & responds to them quickly.
• A real time system should not be late in response to one event.
• A real time should have well defined timeconstraints.
• Realtime systems are of two types:
1. Hard Real Time Systems

Shruthi.P, Dept CSE, GAT Page 12


OPERATING SYSTEMS - 18CS43 2021
2. Soft Real Time Systems
1. A hard real time system guarantees that the critical tasks to be completed on time.
This goal requires that all delays in the system be bounded from the retrieval of
stored data to time that it takes the OS to finish the request.
2. Soft real time system is a less restrictive one where a critical real time task gets
priority over other tasks & retains the property until it completes. Soft real time
system is achievable goal that can be mixed with other type of systems. They have
limited utility than hard real time systems. Soft real time systems are used in area
of multimedia, virtual reality & advanced scientific projects. It cannot be used in
robotics or industrial controls due to lack of deadline support. Soft real time
requires two conditions to implement. They are CPU scheduling must be priority
based & dispatch latency should be small.

COMPUTING ENVIRONMENTS
Different types of computing environments are:
• Traditional Computing.
• Web Based Computing.
• Embedded Computing.

Traditional Computing Typical office environment uses traditional computing.


NormalPC is used in traditional computing environment. N/w computers are essential
terminals that understand web based computing. In domestic application most of the user
had a single computer with internet connection. Cost of accessing internet is high.
Web Based Computing has increased the emphasis on N/w. Web based computing
usesPC, handheld PDA & cell phones. One of the feature of this type is load balancing. In
load balancing, N/w connection is distributed among a pool of similar servers.
Embedded computing uses real time OS. Application of
embeddedcomputing is car engines, manufacturing robots, microwave ovens.
This type of system provides limited features.

OPERATING SYSTEM SERVICES:


An operating system provides an environment for the execution of programs. It provides
certain services to programs and to the users of those programs. The specific services
provided, of course, differ from one operating system to another, but we can identify
common classes. These operating-system services are provided for the convenience of the
programmer, to make the programming task easier.

One set of operating-system services provides functions that are helpful to the user.

• User interface: Almost all operating systems have a user interface (UI).
Thisinterface can take several forms. One is a command-line interface (CLI),
which uses text commands and a method for entering them (say, a program to allow
entering and editing of commands). Another is a batch interface, in which
commands and directives to control those commands are entered into files, and
those files are executed. Most commonly a graphical user interface (GUI) is
used. Here, the interface is a window system with a pointing device to direct I/O,
choose from menus, and make selections and a keyboard to enter text. Some
systems provide two or all three of these variations.
• Program execution: The system must be able to load a program into memory
andto run that program. The program must be able to end its execution, either
normally or abnormally (indicating error).

Shruthi.P, Dept CSE, GAT Page 13


OPERATING SYSTEMS - 18CS43 2021
• I/O operations: A running program may require I/O, which may involve a file
oran I/O device. For specific devices, special functions may be desired (such as
recording to a CD or DVD drive or blanking a CRT screen). For efficiency and
protection, users usually cannot control I/O devices directly. Therefore, the
operating system must provide a means to do I/O.
• File-system manipulation: The file system is of particular interest.
Obviously,programs need to read and write files and directories. They also need to
create and delete them by name, search for a given file, and list file information.
Finally, some programs include permissions management to allow or deny access
to files or directories based on file ownership.
• Communications: There are many circumstances in which one process needs
toexchange information with another process. Such communication may occur
between processes that are executing on the same computer or between processes
that are executing on different computer systems tied together by a computer
network. Communications may be implemented via shared memory or through
message passing, in which packets of information are moved between processes by
the operating system.
• Error detection: The operating system needs to be constantly aware of
possibleerrors. Errors may occur in the CPU and memory hardware (such as a
memory error or a power failure), in I/O devices (such as a parity error on tape, a
connection failure on a network, or lack of paper in the printer), and in the user
program (such as an arithmetic overflow, an attempt to access an illegal memory
location, or a too-great use of CPU time). For each type of error, the operating
system should take the appropriate action to ensure correct and consistent
computing. Debugging facilities can greatly enhance the user's and programmer's
abilities to use the system
efficiently.
Another set of operating-system functions exists not for helping the user but rather for
ensuring the efficient operation of the system itself. Systems with multiple users can gain
efficiency by sharing the computer resources among the users.
• Resource allocation: When there are multiple users or multiple jobs running at
thesame time, resources must be allocated to each of {hem. Many different types of
resources are managed by the operating system. Some (such as CPU cycles, main
memory, and file storage) may have special allocation code, whereas others (such
as I/O devices) may have much more general request and release code. For
instance, in determining how best to use the CPU, operating systems have CPU-
scheduling routines that take into account the speed of the CPU, the jobs that must
be executed, the number of registers available, and other factors. There may also be
routines to allocate printers, modems, USB storage drives, and other peripheral
devices.
• Accounting: We want to keep track of which users use how much and what
kindsof computer resources. This record keeping may be used for accounting (so
that users can be billed) or simply for accumulating usage statistics. Usage statistics
may be a valuable tool for researchers who wish to reconfigure the system to
improve computing services.
• Protection and Security: The owners of information stored in a multi-user
ornetworked computer system may want to control use of that information. When
several separate processes execute concurrently, it should not be possible for one
process to interfere with the others or with the operating system itself. Protection
involves ensuring that all access to system resources is controlled. Security of the
system from outsiders is also important. Such security starts with requiring each
user to authenticate him or her to the system, usually by means of a password, to
gain access to system resources. It extends to defending external I/O devices,

Shruthi.P, Dept CSE, GAT Page 14


OPERATING SYSTEMS - 18CS43 2021
including modems and network adapters, from invalid access attempts and to
recording all such connections for detection of break-ins. If a system is to be
protected and secure, precautions must be instituted throughout it. A chain is only
as strong as its weakest link.

USER OPERATING SYSTEM INTERFACE


Command Interpreter System:
• Command interpreter is a special program in UNIX & MS DOS OS i.e. running
when the user logs on.
• Many commands are given to the OS through control statements when the user logs
on; a program that reads & interprets control statements is executed automatically.
• This program is sometimes called the control card interpreter or command line
interpreter and is also called as shell.
• The command statements themselves deal with process creation & management,
I/O handling, secondary storage management, main memory management, file
system access, protection & N/w.

System Calls:
• System provides interface between the process & the OS.
• The calls are generally available as assembly language instruction.
• Several languages have been defined to replace assembly language program.
• A system call instruction generates an interrupt and allows OS to gain control of the
processors.
• System calls occur in different ways depending on the computer.
• Some time more information is needed to identify the desired system call.
• The exact type & amount of information needed may vary according to the
particular OS & call.
Example of System call: The sequence of system calls used to write a simple program to read
data from one file to another file are as follows:
• The first input will be the names of the two files: the input file and the output file.
• The file names can be obtained using read () system call i.e., to write a prompting
message on the screen and then to read from the keyboard the characters that
define the two files.
• Once the two files are obtained, the program will open the input file and create the
output file by using open () and create () system call.
• When the program tries to open the input file, it may find that there is no file of
that name or that file is protected against access. In these cases, the program will
print a message on the console and then terminate abnormally. If the input file
exists, then a new output file will be created using create () system call. If the
output file already exists then, the program will abort using abort () system calls
or may delete the existing file and create a new output file.
• Now both the files will be set up and we enter a loop that reads from the input file
and writes to the output file. Each read and write must return status information
regarding possible error conditions.
• Finally, after the entire file is copied, the program may close both files, write a
message on the console and finally terminate normally. The following diagram
depicts the example of how the system calls are used.
The following diagram depicts the example:

Shruthi.P, Dept CSE, GAT Page 15


OPERATING SYSTEMS - 18CS43 2021

Figure: example of how the system calls are used


System Call Implementation:
• Typically, a number associated with each system call.
o System-call interface maintains a table indexed according to these numbers.
• The system call interface invokes intended system call in OS kernel and returns status
of the system call and any return values.
• The caller need know nothing about how the system call is implemented.
o Just needs to obey API and understand what OS will do as a result call.
o Most details of OS interface hidden from programmer by API.

Managed by run-time support library (set of functions built into libraries
included with compiler).

Figure: The handling of a user application invoking the open ( ) system call

Passing Parameters to OS:


Three general methods used to pass parameters to the OS:
• Simplest: pass the parameters in registers. In some cases, may be more parameters
than registers.
• Parameters stored in a block, or table, in memory, and address of block passed as
a parameter in a register. This approach taken by Linux and Solaris.
• Parameters placed, or pushed, onto the stack by the program and popped off the
stack by the operating system. Block and stack methods do not limit the number
or length of parameters being passed.

Shruthi.P, Dept CSE, GAT Page 16


OPERATING SYSTEMS - 18CS43 2021

Figure: Passing of parameters as a table.


• Three general methods are used to pass the parameters to the OS. o
The simplest approach is to pass the parameters in registers. o
In some there can be more parameters than register.
o In these the parameters are generally in a block or table in m/y and
theaddress of the block is passed as parameters in register.
o This approach used by Linux.
o Parameters can also be placed or pushed onto stack by the program &
poppedoff the stack by the OS. Some OS prefer the block or stack methods,
because those approaches do not limit the number or length of parameters
being passed.
System Calls Types:
System calls may be grouped roughly into 5 categories as follows:

Process Control
• end, abort
• load, execute create process, terminate process
• get process attributes, set process attributes
• wait for time, wait event, signal event
• allocate and free memory
• create file, delete file
• open, close ,read, write, reposition
• get file attributes, set file attributes

Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices

Information maintenance
• get time or date, set time or date
• get system data, set system data
• get process, file, or device attributes
• set process, file, or device attributes

Communications
• create, delete communication connection
• send, receive messages
• Transfer status information
• attach or detach remote devices

Shruthi.P, Dept CSE, GAT Page 17


OPERATING SYSTEMS - 18CS43 2021
System Programs
System programs provide a convenient environment for program development and execution.
The can be divided into:
• File manipulation
• Status information
• File modification
• Programming language support
• Program loading and execution
• Communications
• Application programs
Example:-Most systems have the system calls to return the current time & date, number
of current users, version number of OS, amount of free m/y or disk space & so on.
In addition the OS keeps information about all its processes & there are system calls to
access this information.

COMMUNICATION: There are two modes of communication:


1. Message Passing Models
2. Shared Memory
1. Message Passing Models:
• In this information is exchanged using inter-process communication facility
provided by OS.
• Before communication the connection should be opened.
• The name of the other communicating party should be known, it can be on the same
computer or it can be on another computer connected by a computer network.
• Each computer in a network may have a host name.
• The recipient process must give its permission for communication to take place
with an accept connection call.
• Most processes receive the connection through special purpose system program
dedicated for that purpose called daemons.
2. Shared Memory:
• The processes use the map m/y system calls to gain access to m/y owned by another
process.
• They exchange information by reading and writing data in shared areas.
• These areas are located by these processes and not under OS control.
• They should ensure that they are not writing to same m/y area.
• Message passing is useful when small number of data need to be exchanged since no
conflicts are to be avoided and it is easier to implement than in shared memory.
• Shared memory allows maximum speed and convenience of communication as it
is done at memory speed when within a computer.

OPERATING SYSTEM DESIGN AND IMPLEMENTATION


FILE MANAGEMENT:
• System calls can be used to create & deleting of files.
• System calls may require the name of the files with attributes for creating &
deleting of files.
• Other operation may involve the reading of the file, write & reposition the file after
it is opened.
• Finally we need to close the file.
• For directories some set of operation are to be performed.
• Sometimes we require resetting some of the attributes on files &
directories.
Shruthi.P, Dept CSE, GAT Page 18
OPERATING SYSTEMS - 18CS43 2021
• The system call get file attribute & set file attribute are used for this type of
operation.

DEVICE MANAGEMENT:
• The system calls are also used for accessing devices.
• Many of the system calls used for files are also used for devices.
• In multi user environment
• The requirements are made to use the device.
• After using the device must be released using release system call the device is free
to be used by another user.
o These functions are similar to open & close system calls of files.
• Read, write & reposition system calls may be used with devices.
• MS-DOS & UNIX merge the I/O devices & the files to form file services
structure.
• In file device structure I/O devices are identified by file names.

OPERATING SYSTEM STRUCTURES


• Modern OS is large & complex.
• OS consists of different types of components.
• These components are interconnected & melded into kernel.
For designing the system different types of structures are used. They are:
1. Simple structures.
2. Layered structured.
3. Micro kernels
4. Modules

1. Simple Structures
• Simple structure OS are small, simple & limited systems.
• The structure is not well defined.
• MS-DOS is an example of simple structure OS.

MS-DOS layer structure is shown below.

Figure: MS-DOS layer structure

UNIX consisted of two separate modules:


a. Kernel
b. The system programs.
Kernel is further separated into:
• Series of interfaces & device drivers which were added & expanded as the UNIX
evolved over years.
• The kernel also provides the CPU scheduling, file system, m/y management &
other OS function through system calls.

Shruthi.P, Dept CSE, GAT Page 19


OPERATING SYSTEMS - 18CS43 2021
• System calls define API to UNIX and a system program commonly available
defines the user interface.
• The programmer and the user interface determine the context that the kernel must
support.
• New versions of UNIX are designed to support more advanced H/w.
• The OS can be broken down into large number of smaller components which are
more appropriate than the original MS-DOS.

2. Layered Approach:
• In this OS is divided into number of layers, where one layer is built on the top
of another layer.
• The bottom layer is hardware and higher layer is the user interface.
• An OS is an implementation of abstract object i.e. the encapsulation of data &
operation to manipulate these data.
• The main advantage of layered approach is the modularity i.e. each layer uses the
services & functions provided by the lower layer.
• This approach simplifies the debugging & verification.
• Once first layer is debugged the correct functionality is guaranteed while
debugging the second layer.
• If an error is identified then it is a problem in that layer because the layer below it
is already debugged.
• Each layer is designed with only the operations provided by the lower level layers.
• Each layer tries to hide some data structures, operations & hardware from the
higher level layers.
• A problem with layered implementation is that they are less efficient then the
other types.
• The following diagram depicts the layered approach:

Figure: Layered Approach


• UNIX – limited by hardware functionality, the original UNIX operating system
had limited structuring. The UNIX OS consists of two separable parts
o Systems programs
o The kernel
• Consists of everything below the system-call interface and above the physical
hardware
• Provides the file system, CPU scheduling, memory management, and other
operating-system functions; a large number of functions for one level.
• The UNIX system structure is a s shown below:

Shruthi.P, Dept CSE, GAT Page 20


OPERATING SYSTEMS - 18CS43 2021

Figure: UNIX system structure

3. Micro Kernels:
• Micro kernel is a small Os which provides the foundation for modular extensions.
• The main function of the micro kernels is to provide communication facilities
between the current program and various services that are running in user space.
• This approach was supposed to provide a high degree of flexibility and
modularity.
• The benefit of this approach is as follows:
o Easier to extend a microkernel
o Easier to port the operating system to new architectures o
More reliable (less code is running in kernel mode)
o More secure
• All the new services are added to the user space & do not need the modification
of kernel.
• This approach also provides more security & reliability.
• Most of the services will be running as user process rather than the kernel process.
• This was popularized by use in Mach OSX Structure and the diagram is as shown
below:

Figure: Mach OSX Structure


• A micro kernel in Windows NT provides portability and modularity.
• Kernel is surrounded by a number of compact sub systems so that task of
implementing NT on variety of platform is easy.
• Micro kernel architecture assigns only a few essential functions to the kernel
including address space, IPC & basic scheduling.
• QNX is the RTOS i.e. also based on micro kernel design.

4. Modules:
• Most modern operating systems implement kernel modules.
• Uses object-oriented approach.
• Each core component is separate.

Shruthi.P, Dept CSE, GAT Page 21


OPERATING SYSTEMS - 18CS43 2021
• Each talks to the others over known interfaces.
• Each is loadable as needed within the kernel.
• Overall, similar to layers but with more flexible.
• Example Solaris Modular approach:

Figure: Solaris Modular approach

Is separation of mechanism and policy desirable while designing an operating


system? Discuss with an example.
• Policy: It determines what will be done?
• Mechanism: It determines how to do something?
• Yes the separation of mechanism and policy is desirable while designing an operating
system.
• For example, consider a mechanism for giving priority to certain types of programs
over others. If the mechanism is properly separated from policy, it can be used either
to support a policy decision that I/O-intensive programs should have priority over
CPU-intensive ones or to support the opposite policy.

VIRTUAL MACHINES (VM)


• It treats hardware and the os kernel as though they were all hardware.
• A VM provides an interface identical to the underlying bare hardware.
• The operating system creates the illusion of multiple processes, each executing on its
own processor with its own (virtual) memory.
• The resources of the physical computer are shared to create the virtual machines.

• CPU scheduling can create the appearance that users have their own processor.
• Spooling and a file system can provide virtual card readers and virtual line printers.

Figure: (a) NON-VIRTUAL MACHINE (b) VIRTUAL MACHINE

Advantages and Disadvantages of Virtual Machines

Shruthi.P, Dept CSE, GAT Page 22


OPERATING SYSTEMS - 18CS43 2021
• The virtual-machine concept provides complete protection of system resources since
each vm is isolated from all other virtual machines.
• This isolation, however, permits no direct sharing of resources.
• A vm system is a perfect vehicle for os research and development.
• System development is done on the virtual machine, instead of on a physical machine
and so does not disrupt normal system operation.
• The virtual machine concept is difficult to implement due to the effort required to
provide an exact duplicate to the underlying machine.

VMware Architecture:

Figure: VMware Architecture

Java Virtual Machine:


• Compiled Java programs are platform-neutral byte codes executed by a Java Virtual
Machine (JVM).
• JVM consists of -class loader -class verifier -runtime interpreter
• Just-In-Time (JIT) compilers increase performance

Figure: JAVA VIRTUAL MACHINE

OPERATING SYSTEM GENERATION:


User goals –operating system should be convenient to use, easy to learn, reliable, safe,
andfast.
System goals –operating system should be easy to design, implement, and maintain, as well
as flexible, reliable, error-free, and efficient.
Mechanisms: Determine how to do something.

Shruthi.P, Dept CSE, GAT Page 23


OPERATING SYSTEMS - 18CS43 2021
Policies: decide what will be done.
The separation of policy from mechanism is a very important principle, it allows maximum
flexibility if policy decisions are to be changed later.
Traditionally written in assembly language, operating systems can now be written in higher-
level languages.
Code written in a high-level language:

can be written faster.

is more compact.

is easier to understand and debug.
An operating system is far easier to port (move to some other hardware) if it is written
in a high-level language.

SYSTEM BOOT:
• Operating systems are designed to run on any of a class of machines; the system must
be configured for each specific computer site.
• SYSGEN program obtains information concerning the specific configuration of the
hardware system.
• Booting – starting a computer by loading the kernel.
• Bootstrap program – code stored in ROM that is able to locate the kernel, load it into
memory, and start its execution.

Process Concept

Process:
• A process is a program in execution.
• A process is more than the program code, which is sometimes known as the
textsection.
• The process includes
o the current activity, as represented by the value of the program counter.
o the processstack,which contains temporary data.
o adata section,which contains global variables.
o aheap,which is memory that is dynamically allocated during process runtime.

Figure: A Process in memory


• A program is a passive entity, such as a file containing a list of
instructions stored on disk (often called an executable file).

Shruthi.P, Dept CSE, GAT Page 24


OPERATING SYSTEMS - 18CS43 2021
• A process is an active entity, with a program counter specifying the
next instruction to execute and a set of associated resources.
• A program becomes a process when an executable file is loaded into memory.
• Two common techniques for loading executable files:
• double-clicking an icon representing the executable file and
• entering the name of the executable file on the command line (prgm. exe or a.
out.)
Process State:
• As a process executes, it changes state.
• The state of a process is defined in part by the current activity of that process.

Figure: Process State

Each process may be in one of the following states:


1. New. The process is being created.
2. Running. Instructions are being executed.
3. Waiting. The process is waiting for some event to occur ( I/O completion or
receptionof a signal).
4. Ready. The process is waiting to be assigned to a processor.
5. Terminated. The process has finished execution.

Process Control Block

Figure: Process Control Block

Each process is represented in the operating system by a processcontrol


block (PCB)—also called a task control block.
• Process state: The state may be new, ready, running,
waiting,halted, and soon.

Shruthi.P, Dept CSE, GAT Page 25


OPERATING SYSTEMS - 18CS43 2021
• Program counter: The counter indicates the address of the
nextinstruction to be executed for this process.
• CPU registers. The registers vary in number and type, depending on
the computer architecture. They include accumulators, index
registers, stack pointers, and general-purpose registers, plus any
condition-code information.
• CPU-scheduling information: This information includes a
processpriority, pointers to scheduling queues, and any other
scheduling parameters.
• Memory-management information: include value of the base
andindex registers, the page tables, or the segment tables.
• Accounting information: This includes the amount of CPU and
realtime used, time limits, account numbers, job or process numbers,
and so on.
• I/O status information: This information includes the list of
I/Odevices allocated to the process, a list of open files, and so on.
The PCB simply serves as the repository for any information that may vary from process to
process.

Threads: A single thread of control allows the process to perform only one task at one time.
Example: The user cannot simultaneously type in characters and run the
spell checker within the same process. Many modern operating systems have
extended the process concept to allow a process to have multiple threads of
execution and thus to perform more than one task at a time.

CPU Switch from Process to Process:

Figure: Process Switching

Process Scheduling:
• The objective of multiprogramming is to have some process running
at all times, to maximize CPU utilization.
• The objective of time sharing is to switch the CPU among processes
so frequently that users can interact with each program while it is
running.
• The process scheduler selects an available process (possibly from a
set of several available processes) for program execution on the CPU.

Shruthi.P, Dept CSE, GAT Page 26


OPERATING SYSTEMS - 18CS43 2021
• For a single-processor system, there will never be more than one
running process. If there are more processes, the rest will have to wait
until the CPU is free and can be rescheduled.

Scheduling Queues:
Job queue:
• As processes enter the system, they are put into a job queue.
• This consists of all processes in the system.
Ready queue
• The processes that are residing in main memory and are ready and
waiting to execute are kept on a list called the ready queue.
• This queue is generally stored as a linked list.

Queuing diagram:

Figure: Queuing diagram representation of process scheduling


• Each rectangular box represents a queue.
• Two types of queues are present: the ready queue and a set of device queues.
• The circles represent the resources that serve the queues.
• The arrows indicate the flow of processes in the system.
• A new process is initially put in the ready queue. It waits there until it is selected for
execution, or is dispatched.
Once the process is allocated the CPU and is executing, one of several events could occur:
• The process could issue an I/O request and then be placed in an I/O queue.
• The process could create a new sub process and wait for the sub process's termination.
• The process could be removed forcibly from the CPU, as a result of
an interrupt, and be put back in the ready queue.
In the first two cases, the process eventually switches from the waiting state
to the ready state and is then put back in the ready queue. A process
continues this cycle until it terminates, at which time it is removed from all
queues and has its PCB and resources de-allocated.

Shruthi.P, Dept CSE, GAT Page 27


OPERATING SYSTEMS - 18CS43 2021
Schedulers:
• A process migrates among the various scheduling queues throughout its lifetime.
• The operating system must select, for scheduling purposes, processes
from these queues in some fashion.
• The selection process is carried out by the appropriate scheduler.
• In a batch system, more processes are submitted than can be executed
immediately. These processes are spooled to a disk, where they are
kept for later execution.
• The long-term scheduler, or job scheduler, selects processes from pool
and loads them into memory for execution.
• The short-term scheduler, or CPU scheduler, selects from among the
processes that are ready to execute and allocates the CPU to one of
them.
Note:
1. A I/O-bound process is one that spends more of its time doing I/O
than it spends doing computations.
2. A CPU-bound process generates I/O requests infrequently, using
more of its time doing computations.

Figure: Addition of medium term scheduling to the queuing diagram

Context Switch
• The task of Switching the CPU to another process by performing a
state save of the current process and a state restore of a different
process.
• Perform a state save of the current state of the CPU, be it in kernel
or user mode, and then a state restore to resume operations.
• When a context switch occurs, the kernel saves the context of the
old process in its PCB and loads the saved context of the new
process scheduled to run.
• Context-switch time is pure overhead, because the system does no
useful work while switching.
• Its speed varies from machine to machine, depending on the
memory speed, the number of registers that must be copied, and
the existence of special instructions.
• Typical speeds are a few milliseconds.
• Context-switch times are highly dependent on hardware support.
• A context switch here simply requires changing the pointer to the
current register set.

Operations on Processes:
The processes in most systems can execute concurrently, and they may be
created and deleted dynamically.

Shruthi.P, Dept CSE, GAT Page 28


OPERATING SYSTEMS - 18CS43 2021
1. Process Creation: A process may create several new processes, via a create-
processsystem call, during the course of execution. The creating process is called a
parent process. The new processes are called the children of that process. Each of
these new processes may in turn create other processes, forming a tree of processes.
Operating systems identify processes according to a unique process identifier (or
pid), which is typically an integer number.

Figure: A tree of processes on a typical Solaris system

• The process at the top of the tree is the sched process, with pid of 0.
• The sched process creates several children processes—including
pageout and fsflush. These processes are responsible for
managing memory and file systems.
• The sched process also creates the init process, which serves as
the root parent process for all user processes.
• Two children of init—inetd and dtlogin. inetd is responsible for networking services
such as telnet and ftp;
• dtlogin is the process representing a user
login screen. which in turns creates the
sdt_shel process.
• Below sdt_shel, a user's command-line shell—the C-shell or csh—is created.
• We also see a csh process with pid of 7778 representing a user who
has logged onto the system using telnet .
• This user has started the Netscape browser (pid of 7785) and the emacs editor (pid of
8105).
• When a process creates a new process, two possibilities exist in terms of execution:
o The parent continues to execute concurrently with its children.
o The parent waits until some or all of its children have terminated.
• There are also two possibilities in terms of the address space of the new process:
o The child process is a duplicate of the parent process (it has
the same program and data as the parent).
o The child process has a new program loaded into it.

C program forking separate process:

int main( )
{
pid_t pid;
/* fork another process */
pid=fork();
if (pid < 0) { /* error occurred */

Shruthi.P, Dept CSE, GAT Page 29


OPERATING SYSTEMS - 18CS43 2021
fprintf(stderr, "Fork Failed"); exit(-1);}
else if (pid == 0)
{ /* child process */
execlp("/bin/ls",
"ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf("Child Complete");
exit(0);
}
}

Figure: Processes creation using fork( ) system call.

• In UNIX: each process is identified by its process identifier(PID).


• A new process is created by the fork( ) system call.
• The new process consists of a copy of the address space of the original process.
• This mechanism allows the parent process to communicate easily with its child
process.
• The parent and the child continue execution at the instruction after the
fork( ), with one difference:
• The return code for the fork( ) is zero for the new (child) process
• The (nonzero) process identifier of the child is returned to the parent.
• Typically, the exec( ) system call is used after a fork( ) system call by one of the two
processes.
• exec( ) replace the process's memory space with a new program.
• The exec ( ) system call loads a binary file into memory and starts its execution.
• The parent can then create more children; or, if it has nothing else to
do while the child runs, it can issue a wait ( ) system call to move
itself off the ready queue until the termination of the child.
• Example-1: the UNIX system calls:
o Two different processes running a copy of the same program.
The value of pid for the child process is zero; pid for the
parent is an integer value greater than zero.
o The parent waits for the child process to complete with the
wait ( ) system call.
o When the child process completes by invoking exit ( ) the
parent process resumes from the call to wait ( ) , where it
completes using the exit ( ) system call.
• Example-2: process creation in Windows:
o Processes are created in the Win32 API using the CreateProcess ( ) function.
However, whereas fork () has the child process inheriting the address space of

Shruthi.P, Dept CSE, GAT Page 30


OPERATING SYSTEMS - 18CS43 2021
its parent, CreateProcess ( ) requires loading a specified program into the
address space of the child process at process creation. Furthermore, whereas
fork ( ) is passed no parameters, CreateProcess ( ) expects no fewer than ten
parameters. The first two parameters passed to CreateProcess ( ) are the
application name and command line parameters. If the application name is
NULL, the command line parameter specifies the application to load.
2) Process Termination:
• A process terminates when it finishes executing its final statement
and asks the operating system to delete it by using the exit () system
call.
• At that point, the process may return a status value to its parent process.
• All the resources of the process—including physical and virtual
memory, open files and I/O buffers—are deallocated by the operating
system.
• A process can cause the termination of another process via an appropriate system call.
• Such a system call can be invoked only by the parent of the process that is to be
terminated.
• A parent may terminate the execution of one of its children for a variety of reasons: o
The child has exceeded its usage of some of the resources that it has been
allocated.
o The task assigned to the child is no longer required.
o The operating system does not allow a child to continue if its parentterminates.
Cascading termination:
Some systems, do not allow a child to exist if its parent has terminated. In such systems, if a
process terminates (either normally or abnormally), then all its children must also be
terminated. In UNIX, we can terminate a process by using the exit() system call; Its parent
process may wait for the termination of a child process by using the wait( ) system call.
3) Interprocess Communication:
Independent process
• A process is independent if it cannot affect or be affected by
the other processes executing in the system.
• A process that does not share data with any other process.
Cooperating process
• A process is cooperating if it can affect or be affected by the
other processes executing in the system. A process that shares
data with other processes.
There are several reasons for providing an environment that allows process cooperation:
a. Information sharing: Since several users may be interested in
thesame piece of information (for instance, a shared file), we must
provide an environment to allow concurrent access to such
information.
b. Computation speedup: If we want a particular task to run faster,
wemust break it into subtasks, each of which will be executing in
parallel with the others. Such a speedup can be achieved only if the
computer has multiple processing elements (such as CPUs or I/O
channels).
c. Modularity: To construct the system in a modular fashion, divide
thesystem functions into separate processes or threads.
d. Convenience: Even an individual user may work on many tasks atthe
same time. For instance, a user may be editing, printing, and
compiling in parallel.
Shruthi.P, Dept CSE, GAT Page 31
OPERATING SYSTEMS - 18CS43 2021
Cooperating processes require an InterProcess Communication (IPC)
mechanism that will allow them to exchange data and information.
There are two fundamental models of interprocess communication:
a. Message passing
b. Shared memory

Figure: Communication models (a) Message passing model (b) Shared memory model

In the message-passing model:


• Communication takes place by means of messages exchanged
between the cooperating processes.
• Message passing is useful for exchanging smaller amounts of data,
because no conflicts need be avoided.
• Message passing is also easier to implement than is shared memory for intercomputer
communication.
• Message-passing systems are typically implemented using system
calls and thus require the more time.
In the shared-memory model:
• A region of memory that is shared by cooperating processes is established.
• Processes can then exchange information by reading & writing data to the shared
region.
• Shared memory allows maximum speed and convenience of communication, as it can
be done at memory speeds when within a computer.
• Shared memory is faster than message passing.
• System calls are required only to establish shared-memory regions.

Shared-Memory Systems
• Interprocess communication using shared memory requires
communicating processes to establish a region of shared memory.
• A shared-memory region resides in the address space of the process
creating the shared-memory segment.
• Other processes that wish to communicate using this shared-memory
segment must attach it to their address space.
• They can then exchange information by reading and writing data in the shared areas.
• The form of the data and the location are determined by these
processes and are not under the operating system's control.
• The processes are also responsible for ensuring that they are not
writing to the same location simultaneously.

Shruthi.P, Dept CSE, GAT Page 32


OPERATING SYSTEMS - 18CS43 2021
The producer-consumer problem is used to illustrate the concept of cooperating processes
and is as follows:
A producer process produces information that is consumed by a consumer process.
For example, a compiler may produce assembly code, which is consumed by an
assembler.
The assembler, in turn, may produce object modules, which are consumed by the
loader.
One solution to the producer-consumer problem uses shared memory.
To allow producer and consumer processes to run concurrently, we must have
available a buffer of items that can be filled by the producer and emptied by the
consumer.
This buffer will reside in a region of memory that is shared by the producer and
consumer processes.
A producer can produce one item while the consumer is consuming another item. The
producer and consumer must be synchronized, so that the consumer does not try to
consume an item that has not yet been produced.
Producer Process
while (true) {
/* Produce an item */
while (((in = (in + 1) % BUFFER SIZE
count) == out) ; /* do nothing --
no free buffers */
buffer[in] = item;
in = (in + 1) % BUFFER SIZE;

}
Consumer
while (true) {
while (in == out)
; // do nothing
nextConsumed= buffer[out];
out = (out + 1) % BUFFER
SIZE; return item;
}
Two types of buffers can be used. They are:
• The unbounded buffer places no practical limit on the size of
the buffer. The consumer may have to wait for new items, but
the producer can always produce new items.
• The bounded buffer assumes a fixed buffer size. In this case,
the consumer must wait if the buffer is empty, and the
producer must wait if the buffer is full.

Message-Passing Systems
• Message passing provides a mechanism to allow processes to communicate and to
synchronize their actions without sharing the same address space.
• For example, a chat program used on the World Wide Web could be designed so that
chat participants communicate with one another by exchanging messages.
• A message-passing facility provides at least two operations:
o send(message) and receive(message).
• Messages sent by a process can be of either fixed or variable size.
• Fixed-sized messages:
• The system-level implementation is straightforward.

Shruthi.P, Dept CSE, GAT Page 33


OPERATING SYSTEMS - 18CS43 2021
• Makes the task of programming more difficult.
• Require a more complex system-level implementation.
• The programming task becomes simpler.
If processes P and Q want to communicate, they must send messages to
and receive messages from each other; a communication link must exist
between them.
Methods for logically implementing a link and the send()/receive ()
operations:
1. Direct or indirect communication
2. Synchronous or asynchronous communication
3. Automatic or explicit buffering

Naming:
• Direct communication, each process that wants to communicate must
explicitly name the recipient or sender of the communication.
• send(P, message)—Send a message to process P.
• receive (Q, message)—Receive a message from process Q. A
• A link is associated with exactly two processes. Between each pair of processes, there
exists exactly one link.
o symmetryin addressing: Both the sender process and
thereceiver process must name the other to communicate.
o asymmetryin addressing: Only the sender names therecipient;
the recipient is not required to name the sender.
• In this scheme, the send() and receive () primitives are defined as follows:
o send(P, message)—Send a message to process P.
o receive(id, message)—-Receive a message from any process.
• The disadvantage in both of these schemes (symmetric and
asymmetric) is the limited modularity of the resulting process
definitions.
• Indirect communication, the messages are sent to and received from mailboxes, or
ports.
• A mailbox can be viewed abstractly as an object into which messages
can be placed by processes and from which messages can be
removed.
• Each mailbox has a unique identification.
o send(A, message)—Send a message to mailbox A.
o receive(A, message)—Receive a message from mailbox A.
• In this scheme, a communication link has the following properties:
o A link is established between a pair of processes only if both
members of the pair have a shared mailbox.
o A link may be associated with more than two processes.
o Between each pair of communicating processes, there may be
a number of different links, with each link corresponding to
one mailbox.
• A mailbox may be owned either by a process or by the operating system.
o Create a new mailbox.
o Send and receive messages through the mailbox.
o Delete a mailbox.

Synchronization

Shruthi.P, Dept CSE, GAT Page 34


OPERATING SYSTEMS - 18CS43 2021
• Communication between processes takes place through calls to send() and receive ()
primitives.
• There are different design options for implementing each primitive.
• Message passing may be either blocking or nonblocking— also
known as synchronous and asynchronous.
o Blocking send:The sending process is blocked until
themessage is received by the receiving process or by the
mailbox.
o Nonblocking send:The sending process sends the message and
resumesoperation.
o Blocking receive:The receiver blocks until a message is available.
o Nonblocking receive:The receiver retrieves either a valid message or a
null.Different combinations of send() and receive () are possible.

Buffering: Whether communication is direct or indirect, messages exchanged


bycommunicating processes reside in a temporary queue. Basically, such queues can be
implemented in three ways:
1. Zero capacity
2. Bounded capacity
3. Unbounded capacity
1. Zero capacity:
• The queue has a maximum length of zero.
• The link cannot have any messages waiting in it.
• In this case, the sender must block until the recipient receives the message.
2. Bounded capacity:
• The queue has finite length n; thus, at most n messages can reside in it.
• If the queue is not full when a new message is sent, the message is
placed in the queue and the sender can continue execution without
waiting.
• The links capacity is finite, however. If the link is full, the sender
must block until space is available in the queue.
3. Unbounded capacity:
• The queues length is potentially infinite.
• Any number of messages can wait in it.
• The sender never blocks.
Note: The zero-capacity case is sometimes referred to as a message
systemwith no buffering; the other cases are referred to as systems with
automatic buffering.

Shruthi.P, Dept CSE, GAT Page 35

You might also like