0% found this document useful (0 votes)
20 views60 pages

Os-Module 1-Notes

An operating system (OS) is system software that serves as an intermediary between users and computer hardware, managing resources and enabling efficient program execution. The document outlines the structure and functions of an OS, including its role as a resource allocator, control program, and the organization of computer systems, including single-processor and multiprocessor systems. It also discusses memory management, I/O structure, and the concept of distributed systems, highlighting the importance of efficient resource utilization and user interaction.

Uploaded by

uhsrijan
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)
20 views60 pages

Os-Module 1-Notes

An operating system (OS) is system software that serves as an intermediary between users and computer hardware, managing resources and enabling efficient program execution. The document outlines the structure and functions of an OS, including its role as a resource allocator, control program, and the organization of computer systems, including single-processor and multiprocessor systems. It also discusses memory management, I/O structure, and the concept of distributed systems, highlighting the importance of efficient resource utilization and user interaction.

Uploaded by

uhsrijan
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/ 60

MODULE – 1

INTRODUCTION TO OPERATING SYSTEM

What is an Operating System?


An operating system is system software that acts as an intermediary between a user of a computer and
the computer hardware. It is software that manages the computer hardware. Operating system allows
the user to execute programs in a convenient and efficient manner.

Operating system goals:


• Make the computer system convenient to use. It hides the difficulty in managing the hardware.
• Use the computer hardware in an efficient manner
• Provide and environment in which user can easily interface with computer.
• It is a resource allocator

Computer System Structure (Components of Computer System)


Computer system mainly consists of four components-
• Hardware – provides basic computing resources
✓ CPU, memory, I/O devices
• Operating system
✓ Controls and coordinates use of hardware among various applications and users
• Application programs – define the ways in which the system resources are used to solve the
computing problems of the users
✓ Word processors, compilers, web browsers, database systems, video games
• Users
✓ People, machines, other computers

The basic hardware components comprises of CPU, memory, I/O devices. The application
program uses these components. The OS controls and co-ordinates the use of hardware, among
various application programs (like compiler, word processor etc.) for various users. The OS allocates
the resources among the programs such that the hardware is efficiently used. The operating system is
the program running at all the times on the computer. It is usually called as the kernel.

Kernel functions are used always in system, so always stored in memory. Non kernel functions are
stored in hard disk, and it is retrieved whenever required.
Views of OS
Operating System can be viewed from two viewpoints–
1. User views 2. System views

1. User Views:-
The user’s view of the operating system depends on the type of user.
1. If the user is using standalone system, then OS is designed for ease of use and high
performances. Here resource utilization is not given importance.
2. If the users are at different terminals connected to a mainframe or minicomputers, by
sharing information and resources, then the OS is designed to maximize resource utilization.
OS is designed such that the CPU time, memory and i/o are used efficiently and no single user
takes more than the resource allotted to them.
3. If the users are in workstations, connected to networks and servers, then the user have a system
unit of their own and shares resources and files with other systems. Here the OS is designed for
both ease of use and resource availability (files).
4. Users of hand held systems, expects the OS to be designed for ease of use and performance per
amount of battery life
5. Other systems like embedded systems used in home devices (like washing m/c) & automobiles do
not have any user interaction. There are some LEDs to show the status of its work

2. System Views:-
Operating system can be viewed as a resource allocator and control program.
i. Resource allocator - The OS acts as a manager of hardware and software resources. CPU
time, memory space, file-storage space, I/O devices, shared files etc. are the different resources
required during execution of a program. There can be conflicting request for these resources by
different programs running in same system. The OS assigns the resources to the requesting
program depending on the priority
ii. Control Program – The OS is a control program and manage the execution of user program 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. Each device controller is in-charge of a specific type of device. To ensure orderly access to
the shared memory, a memory controller is provided whose function is to synchronize access to the
memory. The CPU and other devices execute concurrently competing for memory cycles. Concurrent
execution of CPUs and devices competing for memory cycles.

When system is switched on,


1. ‘Bootstrap’ program is executed. It is the initial program to run in the system. This program is
stored in read-only memory (ROM) or in electrically erasable programmable read-only
memory(EEPROM).
2. It initializes the CPU registers, memory, device controllers and other initial setups.
3. The program also locates and loads, the OS kernel to the memory.
4. Then the OS starts with the first process to be executed (ie. ‘init’ process) and then wait for the
interrupt from the user.

.
Interrupt handling
The occurrence of an event is usually signaled by an interrupt. The interrupt can either be from the
hardware or the software. Hardware may trigger an interrupt at any time by sending a signal to the
CPU. Software triggers an interrupt by executing a special operation called a system call (also called
a monitor call).
• When the CPU is interrupted, it stops what it is doing and immediately transfers execution
to a fixed location.
• The fixed location (Interrupt Vector Table) contains the starting address where the service routine
for the interrupt is located.
• After the execution of interrupt service routine, the CPU resumes the interrupted computation.

Interrupts are an important part of computer architecture. Each computer design has its own interrupt
mechanism, but several functions are common. The interrupt must transfer control to the appropriate
interrupt service routine

Storage Structure

Computer programs must be in main memory (RAM) to be executed. Main memory is the large
memory that the processor can access directly. It commonly is implemented in a semiconductor
technology called dynamic random-access memory (DRAM). Computers provide Read Only
Memory(ROM), whose data cannot be changed.

All forms of memory provide an array of memory words. Each word has its own address. Interaction is
achieved through a sequence of load or store instructions to specific memory addresses.
A typical instruction-execution cycle, as executed on a system with a Von Neumann architecture,
• First fetches an instruction from memory and stores that instruction in the instruction
register.
• The instruction is then decoded and may cause operands to be fetched from memory and stored
in some internal register.
• After the instruction on the operands has been executed, the result may be stored back in
memory.

Ideally, we want the programs and data to reside in main memory permanently. This arrangement
usually is not possible for the following two reasons:

1. Main memory is usually too small to store all needed programs and data permanently.
2. Main memory is a volatile storage device that loses its contents when power is turned off.

Thus, most computer systems provide secondary storage as an extension of main memory. The
main requirement for secondary storage is that it will be able to hold large quantities of data
permanently.

The most common secondary-storage device is a magnetic disk, which provides storage for both
programs and data. Most programs are stored on a disk until they are loaded into memory. Many
programs then use the disk as both a source and a destination of the information for their processing.

The wide variety of storage systems in a computer system can be organized in a hierarchy as shown in
the figure, according to speed, cost and capacity. The higher levels are expensive, but they are fast.
As we move down the hierarchy, the cost per bit generally decreases, whereas the access time and
the capacity of storage generally increases.
In addition to differing in speed and cost, the various storage systems are either volatile or
nonvolatile. Volatile storage loses its contents when the power to the device is removed. In the
absence of expensive battery and generator backup systems, data must be written to nonvolatile
storage for safekeeping. In the hierarchy shown in figure, the storage systems above the electronic
disk are volatile, whereas those below are nonvolatile.

An electronic disk can be designed to be either volatile or nonvolatile. During normal operation, the
electronic disk stores data in a large DRAM array, which is volatile. But many electronic-disk devices
contain a hidden magnetic hard disk and a battery for backup power. If external power is interrupted,
the electronic-disk controller copies the data from RAM to the magnetic disk.

Another form of electronic disk is flash memory. Which is popular in cameras and personal digital
assistants (PDAS), in robots and increasingly as removable storage on general-purpose computers.
Flash memory is slower than DRAM but needs no power to retain its contents. Another form of
nonvolatile storage is NVRAM, which is DRAM with battery backup power. This memory can be as
fast as DRAM but has a limited duration in which it is nonvolatile.

I/O Structure
A large portion of operating system code is dedicated to managing I/O, both because of its importance
to the reliability and performance of a system and because of the varying nature of the devices.
Every device have a device controller, maintains some local buffer and a set of special- purpose
registers. The device controller is responsible for moving the data between the peripheral
devices. The operating systems have a device driver for each device controller.
To start an I/O operation,
• The device driver loads the registers within the device controller.
• The device controller, examines the contents of these registers to determine what action to take
(such as "read a character from the keyboard").
• The controller starts the transfer of data from the device to its local buffer.
• Once the transfer of data is complete, the device controller informs the device driver(OS) via an
interrupt that it has finished its operation.
• The device driver then returns control to the operating system, and also returns the data.
• For other operations, the device driver returns status information.

This form of interrupt-driven I/O is fine for moving small amounts of data, but very difficult for bulk
data movement. To solve this problem, direct memory access (DMA) is used.

DMA is 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

Computer System Architecture


Categorized roughly according to the number of general-purpose processors used

1. Single-Processor Systems
Most systems use a single processor. The variety of single-processor systems range from PDAs
through mainframes. On a single-processor system, there is one main CPU capable of executing
instructions from user processes. It contains special-purpose processors, in the form of device-
specific processors, for devices such as disk, keyboard, and graphics controllers.
All special-purpose processors run limited instructions and do not run user processes. These are
managed by the operating system, the operating system sends them information about their next task
and monitors their status.
For example, a disk-controller processor, implements its own disk queue and scheduling algorithm,
thus reducing the task of main CPU. Special processors in the keyboard, converts the keystrokes into
codes to be sent to the CPU.
The use of special-purpose microprocessors is common and does not turn a single- processor system
into a multiprocessor. If there is only one general-purpose CPU, then the system is a single-
processor system.

2. Multiprocessor Systems (parallel systems or tightly coupled systems)


Systems that have two or more processors in close communication, sharing the computer bus, the
clock, memory, and peripheral devices are the multiprocessor systems.

Multiprocessor systems have three main advantages:


1. Increased throughput - In multiprocessor system, as there are multiple processors execution
of different programs take place simultaneously. Even if the number of processors is increased the
performance cannot be simultaneously increased. This is due to the overhead incurred in keeping all
the parts working correctly and also due to the competition for the shared resources. The speed-up
ratio with N processors is not N, rather, it is less than N. Thus the speed of the system is not has
expected.
2. Economy of scale - Multiprocessor systems can cost less than equivalent number of many single-
processor systems. As the multiprocessor systems share peripherals, mass storage, and power supplies,
the cost of implementing this system is economical. If several processes are working on the same data,
the data can also be shared among them.
3. Increased reliability- In multiprocessor systems functions are shared among several processors. If
one processor fails, the system is not halted, it only slows down. The job of the failed processor is
taken up, by other processors.
Two techniques to maintain ‘Increased Reliability’ - graceful degradation & fault tolerant
Graceful degradation – As there are multiple processors when one processor fails other process will
take up its work and the system goes down slowly.
Fault tolerant – When one processor fails, its operations are stopped, the system failure is then
detected, diagnosed, and corrected.

There are two types of multiprocessor systems –


• Asymmetric multiprocessing
• Symmetric multiprocessing
1. Asymmetric multiprocessing – (Master/Slave architecture) Here each processor is assigned a
specific task, by the master processor. A master processor controls the other processors in the system.
It schedules and allocates work to the slave processors.

2) Symmetric multiprocessing (SMP) – All the processors are considered as peers. There is no
master-slave relationship. All the processors have its own registers and CPU, only memory is shared.

The benefit of this model is that many processes can run simultaneously. N processes can run if there
are N CPUs—without causing a significant deterioration of performance. Operating systems like
Windows, Windows XP, Mac OS X, and Linux—now provide support for SMP.

A Dual-Core Design
A recent trend in CPU design is to include multiple compute cores on a single chip. The
communication between processors within a chip is more faster than communication between two
single processors
3. Clustered Systems
Clustered systems are two or more individual systems connected together via network and sharing
software resources. Clustering provides high-availability of resources and services. The service will
continue even if one or more systems in the cluster fail. High availability is generally obtained by
storing a copy of files (s/w resources) in the system.
There are two types of Clustered systems – asymmetric and symmetric
In asymmetric clustering – one system is in hot-stand by mode while the others are running the
applications. The hot-standby host machine does nothing but monitor the active server. If that server
fails, the hot-standby host becomes the active server.
In symmetric clustering – two or more systems are running applications, and are monitoring
each other. This mode is more efficient, as it uses all of the available hardware. If any system fails, its
job is taken up by the monitoring system.
Other forms of clusters include parallel clusters and clustering over a wide-area network (WAN).
Parallel clusters allow multiple hosts to access the same data on the shared storage. Cluster
technology is changing rapidly with the help of SAN(storage-area networks). Using SAN resources
can be shared with dozens of systems in a cluster, that are separated by miles.
Operating-System Structure

Multiprogramming (Batch system) needed for efficiency

• Single user cannot keep CPU and I/O devices busy at all times, Multiprogramming organizes jobs
(code and data) so CPU always has one to execute.
• The jobs are kept initially on the disk in the job pool. A subset of total jobs in system is kept in
memory.
• Operating system picks and begins to execute one of the jobs in memory. When it has to wait (for
I/O for example), OS switches to another job.
• System resources are utilized efficiently. There is no user interaction with the computer system.

Memory Layout for Multiprogrammed System


Timesharing (multitasking)

• Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that
users can interact with each job while it is running, creating interactive computing
• User gives instructions to the OS or to a program directly, using a i/p device and waits for immediate
results on the o/p device.
Response time should be < 1 second
• Each user is given the impression that the entire computer system is dedicated to his use.
• Each user has at least one program executing in memory which is called process.
• When a process executes, it executes for only a short time before it finishes or needs to perform I/O.
I/O may be interactive, rather than let the CPU sit idle during this I/O, OS switches the CPU to the
program of some other user.
• If several jobs are ready to be brought into memory and if there is no enough memory space, then
system must choose among them. Making this decision is job scheduling.
• If several jobs ready to run at the same time. System must choose among them Making this decision
is CPU scheduling.
• For reasonable response time, swapping moves processes in and out of memory.
• Virtual memory allows execution of processes not completely in memory. The main advantage of
virtual memory scheme is that it enables users to run programs that are larger than actual physical
memory.

Distributed Systems
• Individual systems that are connected and share the resource available in network is called
Distributed system. Access to a shared resource increases computation speed, functionality, data
availability, and reliability.
• A network is a communication path between two or more systems. Distributed systems depend on
networking for their functionality.
• Networks vary by the protocols used, the distances between nodes, and the transport media.
TCP/IP is the most common network protocol. Most operating systems support TCP/IP.
Operating-System Operations

Modern operating systems are Interrupt driven.

• If there is nothing to be done, Operating system will sit quietly, waiting for something to occur.
• Events are signaled by the occurrence of an interrupt or a trap.
◦ Hardware interrupt by one of the devices
◦ Software interrupt (exception or trap):
▪ Software error (eg., division by zero)
▪ Request for operating system service
▪ Other process problems include infinite loop, processes modifying each other or the operating system
• For each type of interrupt, separate segments of code in the OS determine what action to take.
• Since operating system and the users share the hardware and software resources of the computer
system, we need to make sure that error in a user program could cause problem only for the program.

Dual-Mode Operation
Since the operating system and the user programs share the hardware and software resources of the
computer system, it has to be made sure that an error in a user program cannot cause problems to other
programs and the Operating System running in the system.
The approach taken is to use a hardware support that allows us to differentiate among various modes
of execution.
The system can be assumed to work in two separate modes of operation:
• user mode and
• kernel mode (supervisor mode, system mode, or privileged mode)
• A hardware bit of the computer, called the mode bit, is used 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 by the operating
system and one that is executed by the user.
• When the computer system is executing a user application, the system is in user mode.
• When a user application requests a service from the operating system (via a system call), the
transition from user to kernel mode takes place
• 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 mode bit from 1 to 0). Thus, whenever the operating system gains control
of the computer, it is in kernel mode.
• The dual mode of operation provides us with the means for protecting the operating system
from errant users—and errant users from one another.
• 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.
• Initial control is within the operating system, where instructions are executed in kernel mode.
When control is given to a user application, the mode is set to user mode. Eventually, control is
switched back to the operating system via an interrupt, a trap, or a system call.

Timer
• Operating system uses timer to control the CPU. A user program cannot hold CPU for a long
time, this is prevented with the help of timer.
• A timer can be set to interrupt the computer after a specified period. The period may be fixed
(for example, 1/60 second) or variable (for example, from 1 millisecond to 1 second).
• Fixed timer – After a fixed time, the process under execution is interrupted.
• Variable timer – Interrupt occurs after varying interval. This is implemented using a fixed-
rate clock and a counter. The operating system sets the counter. Every time the clock ticks, the
counter is decremented. When the counter reaches 0, an interrupt occurs.
• Before changing to the user mode, the operating system ensures that the timer is set to
interrupt. If the timer interrupts, control transfers automatically to the operating system, which
may treat the interrupt as a fatal error or may give the program more time.

Process Management
A program under execution is a process. A process needs resources like CPU time, memory, files, and
I/O devices for its execution. These resources are given to the process when it is created or at run time.
When the process terminates, the operating system reclaims the resources.
The program stored on a disk is a passive entity and the program under execution is an active entity.
A single-threaded process has one program counter specifying the next instruction to execute.
The CPU executes one instruction of the process after another, until the process completes. A
multithreaded process has multiple program counters, each pointing to the next instruction to execute
for a given thread.
The operating system is responsible for the following activities in connection with process
management:
• Scheduling process and threads on the CPU
• Creating and deleting both user and system processes
• Suspending and resuming processes
• Providing mechanisms for process synchronization
• Providing mechanisms for process communication

Memory Management
Main memory is a large array of words or bytes. Each word or byte has its own address. Main memory
is the storage device which can be easily and directly accessed by the CPU. As the program executes,
the central processor reads instructions and also reads and writes data from main memory. To improve
both the utilization of the CPU and the speed of the computer's response to its users, general-purpose
computers must keep several programs in memory, creating a need for memory management.
The operating system is responsible for the following activities in connection with memory
management:
• Keeping track of which parts of memory are currently being used by user.
• Deciding which processes and data to move into and out of memory.
• Allocating and deallocating memory space as needed.

Storage Management
There are three types of storage management
i) File system management
ii) Mass-storage management
iii) Cache management.

File-System Management
File management is one of the most visible components of an operating system.A file is a collection of
related information defined by its creator. Commonly, files represent programs and data. Data files
may be numeric, alphabetic, alphanumeric, or binary. Files may be free-form (for example, text files),
or they may be formatted rigidly (for example, fixed fields).
The operating system is responsible for the following activities in connection with file
management:
• Creating and deleting files
• Creating and deleting directories to organize files
• Supporting primitives for manipulating files and directories
• Mapping files onto secondary storage
• Backing up files on stable (nonvolatile) storage media

Mass-Storage Management
As the main memory is too small to accommodate all data and programs, and as the data that it holds
are erased when power is lost, the computer system must provide secondary storage to back up main
memory.
The operating system is responsible for the following activities in connection with disk management:
Free-space management
• Free-space management
• Storage allocation
• Disk scheduling

Caching
• Caching is an important principle of computer systems.
• Information is normally kept in some storage system (such as main memory). As it is used, it is
copied into a faster storage system— the cache—as temporary data.
• When a particular piece of information is required, first we check whether it is in the cache. If
it is, we use the information directly from the cache; if it is not in cache, we use the
information from the source, putting a copy in the cache under the assumption that we will
need it again soon.
• Because caches have limited size, cache management is an important design problem. Careful
selection of the cache size and page replacement policy can result in greatly increased
performance.

Migration of data “A” from Disk to Register

In a hierarchical storage structure, the same data may appear in different levels of the storage system.
For example, suppose to retrieve an integer A from magnetic disk to the processing program.
The operation proceeds by first issuing an I/O operation to copy the disk block on which A resides to
main memory. This operation is followed by copying A to the cache and to an internal register. Thus,
the copy of A appears in several places: on the magnetic disk, in main memory, in the cache, and in an
internal register.

In a multiprocessor environment, in addition to maintaining internal registers, each of the CPUs also
contains a local cache. In such an environment, a copy of A may exist simultaneously in several
caches. Since the various CPUs can all execute concurrently, any update done to the value of A in one
cache is immediately reflected in all other caches where A resides. This situation is called cache
coherency, and it is usually a hardware problem (handled below the operating-system level).

I/O Systems
One of the purposes of an operating system is to hide the peculiarities of specific hardware devices
from the user. The I/O subsystem consists of several components:
• A memory-management component that includes buffering, caching, and spooling
• A general device-driver interface
• Drivers for specific hardware devices

I/O subsystem responsible for


◦ Memory management of I/O including buffering (storing data temporarily while it is being
transferred), caching (storing parts of data in faster storage for performance), spooling (the
overlapping of output of one job with input of other jobs)
◦ General device-driver interface
◦ Drivers for specific hardware devices
• Only device driver knows the peculiarities of the specific device to which it is assigned.

Protection and Security


If a computer system has multiple users and allows the concurrent execution of multiple processes,
then access to data must be regulated.
• Protection – any mechanism for controlling access of processes or users to resources defined by a
computer system. • A system can have adequate protection but still be prone to failure and allow
inappropriate access.(For eg., if authentication information of a user is stolen)
• Security – defense of the system against internal and external attacks .◦ attacks include denial-of-
service, viruses, identity theft, theft of service
• Protection and security require the system to be able to distinguish among all its users, to determine
who can do what.
• Most operating systems maintain a list of user names and associated User identifiers (user Ids).
• User ID is associated with all files, processes of a user to determine access control.
• Group identifier (group ID) allows set of users to be defined.
• Then user's group IDs are also included in the every associated process.
• Privilege escalation allows user to change to effective ID with more rights.

Distributed Systems

• A Distributed Computer System consists of several computer systems, each with its own memory,
connected through networking hardware and software.
• Each computer system could be a PC, a multiprocessor system or a cluster.
• Many resources of a kind eg., many memories, CPUs and I/O devices exist in the distributed system.

Key Benefits:
◦ Resource sharing: Resources can be utilized across the boundaries of individual computer systems.
◦ Reliability: The OS continues to function even when computer systems or resources in it fail.
◦ Computation speedup Processes of an application can be executed in different computer systems to
speed up its completion.
◦ Communication Users can communicate among themselves irrespective of their location in the
system.

A distributed system must integrate the functioning of individual computer systems to achieve the
below benefits.
• Distributed Control: A control function is performed through participation of several nodes,
possibly all nodes in a distributed system.
• Transparency: A resource or service can be accessed without having to know its location in the
distributed system.

• Remote Procedure Call(RPC): A process calls a procedure located in a different computer system.
The OS passes parameters to the remote procedure over the network and returns its result over the
network.
• Distributed control is opposite of the centralized control. Distributed control is essential for ensuring
that failure of a single computer does not halt the operation of the entire system.
• Transparency of a resource or service implies that a user should be able to access it without having to
know which node in the distributed system contains it.
• An Application may employ RPC feature to either perform a part of its computation in another
computer or to access the resource located in that computer.

Special-Purpose Systems
There are different classes of computer systems, whose functions are more limited and specific and it
deal with limited computation domains. The systems can be classified as Real-Time Embedded
Systems, Multimedia Systems and Handheld Systems.

Real-Time Embedded Systems


• Embedded systems vary considerably.
◦ Some are general purpose computers running standard operating systems with special purpose
application to implement the functionality.
◦ Some are hardware devices with a special-purpose embedded operating system providing just the
functionality desired.
◦ Others are hardware devices with application-specific integrated circuits (ASICS) that perform
their task without an OS.
• Embedded systems almost always run real-time operating systems.
• A real-time system is used when rigid time requirements have been placed on the operation of
a processor or the flow of data.
• Users need the computer to perform some action in a timely manner to control the activities in
an external system.
• A real-time system has well defined, fixed time constraints. Processing must be done within
the fixed time constraints, or the system will fail.
◦ Examples of real time systems can be found in missile guidance, air traffic control, display systems
in automobiles, multimedia systems and applications like reservation and banking systems that employ
large databases.

Multimedia Systems
A recent trend in technology is the incorporation of multimedia data into computer systems.
• Multimedia data consists of audio and video files as well as conventional files.
• These data differ from conventional data in that -frames of video must be delivered according to
certain time restrictions.
• Multimedia applications need not be either audio or video, rather a multimedia application often
includes a combination of both. For eg., movie.
• Multimedia describes a wide range of applications
◦ Audio files such as MP3, movies, video conferencing.
◦ Live web-casts of speeches, sporting events and live web-cam.
• Increasingly multimedia applications are being directed toward smaller devices, including PDAs and
cellular telephones.

Handheld Systems

• Developers of handheld systems and applications face many challenges, most of which are due to the
limited size of such devices.
• Because of their size, most handheld devices have small amounts of memory, slow processors and
small display screens.
• The operating system and applications must manage memory efficiently. This includes returning all
allocated memory to the memory manager when the memory is not being used.
• Faster processors require more power. To include a faster processor in a handheld device would
require a large battery, which would take up more space.
• Most handheld devices use smaller, slower processors that consume less power. Therefore OS and
applications must be designed for slow processor.
• The small display screens limit input and output options. Tasks such as reading email and browsing
web pages must be condensed into smaller displays.
• One approach for displaying the content in web pages is web clipping, where only a subset of web-
page is delivered and displayed on the handheld device.

Computing Environments

Traditional Computing
Just a few years ago typical office environment consisted of PCs connected to a network, with servers
providing file and print services.
• Portability was achieved by use of laptop computers.
• Terminals attached to mainframes were also common, with even fewer remote access and portability
options.
◦ Web technologies are stretching the boundaries of traditional computing. Companies establish
portals, which provide web accessibility to their internal servers.
◦ Handheld computers can synchronize with PCs to allow very portable use of the company
information.
• Batch systems processed jobs in bulk, with predetermined input.
• Interactive systems waited for input from users.
• Time sharing systems used a timer and scheduling algorithms to rapidly cycle processes through the
CPU giving each user a share of the resources.

Client-Server Computing

Terminals connected to centralized systems are now being replaced by Pcs.


• As a result, many of today's system act as server systems to satisfy the requests generated by client
systems.
• Compute-server system provides an interface to which a client can send a request to perform an
action, in response server executes the action and sends back results to the client. (eg., database)
• File-server system provides a file-system interface where clients can create, update, read and delete
files
Peer-to-Peer Computing

In this model clients and servers are not distinguished from one another.
• All nodes within the system are considered peers, and each may act as either a client or a server,
depending on whether it is requesting or providing service.
• To participate in a peer-to-peer system, a node must first join the network of peers.
• Once a node has joined the network, it can begin providing services to and requesting services from
other nodes in the system.
• Determining what services are available is accomplished in one of two ways:
• When a node joins a network, it registers its service with a centralized lookup service on the network.
• Any node desiring specific service first contacts this centralized lookup service to determine which
node provides the service.
• The remainder of the communication takes place between the client and the service provider.
• A peer acting as a client must first discover what node provides a desired service by broadcasting a
request for the service to all other nodes in the network.
• The node providing that service responds to the peer making the request.

Web-Based Computing

Web computing has increased the emphasis on networking.


• Devices that were not previously networked now include wired or wireless access.
• Devices that were networked now have faster network connectivity.
• The implementation of web based computing has given rise to new categories of devices, such as
load balancers, which distribute network connections among a pool of similar servers.

System Structure

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.
OS provide services for the users of the system, including:
• User Interfaces - Means by which users can issue commands to the system. Depending on the
operating system these may be a command-line interface ( e.g. sh, csh, ksh, tcsh, etc.), a Graphical
User Interface (e.g. Windows, X-Windows, KDE, Gnome, etc.), or a batch command systems•
Program Execution - The OS must be able to load a program into RAM, run the program, and
terminate the program, either normally or abnormally.
• I/O Operations - The OS is responsible for transferring data to and from I/O devices, including
keyboards, terminals, printers, and files. For specific devices, special functions are provided(device
drivers) by OS.
File-System Manipulation – Programs need to read and write files or directories. The services
required to create or delete files, search for a file, list the contents of a file and change the file
permissions are provided by OS.
• Communications - Inter-process communications, IPC, either between processes running on the
same processor, or between processes running on separate processors or separate machines. May be
implemented by using the service of OS- like shared memory or message passing.
• Error Detection - Both hardware and software errors must be detected and handled appropriately by
the OS. Errors may occur in the CPU and memory hardware (such as power failure and memory
error), 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).
OS provide services for the efficient operation of the system, including:
• Resource Allocation – Resources like CPU cycles, main memory, storage space, and I/O devices
must be allocated to multiple users and multiple jobs at the same time.
• Accounting – There are services in OS to keep track of system activity and resource usage, either
for billing purposes or for statistical record keeping that can be used to optimize future performance.
• Protection and Security – The owners of information(file) in multiuser or networked computer
system may want to control the use of that information. When several separate processes execute
concurrently, one process should not interfere with other or with OS. Protection involves ensuring that
all access to system resources is controlled. Security of the system from outsiders must also be done,
by means of a password.

User Operating-System Interface


There are several ways for users to interface with the operating system.
1) Command-line interface, or command interpreter, allows users to directly enter commands to be
performed by the operating system.
2) Graphical user interface(GUI), allows users to interface with the operating system using pointer
device and menu system.

Command Interpreter
• Some operating systems include the command interpreter in the kernel. Others treat command
interpreter as a special system program.
• On systems with multiple command interpreters to choose from, the interpreters are known as shells.
• The main function of command interpreter is to get and execute the next user specified command.
• Commands can be implemented in two general ways.
◦ Command interpreter itself contains the code to execute the command. In this case number of
commands that can be given determines the size of the command interpreter.
◦ Operating systems implement most commands through system programs. Command Interpreter uses
the command to identify a file to be loaded into memory and executed.
▪ For eg., consider “rm file.txt”
▪ Command Interpreter would search for a file named rm, load the file into memory and execute it
with the parameter file.txt.

Graphical User Interface, GUI

A second approach for interfacing with the operating system is through a user friendly graphical user
interface or GUI.
• The user moves the mouse to position its pointer on images, or icons on the screen that represent
programs, files and directories.
• Clicking a button on the mouse can invoke a program, select a file or a directory or pull down a
menu that contains commands depending on pointer's location.
• Traditionally Unix systems have been dominated by command line interfaces.
• Common Desktop Environment (CDE) and X-windows system are common GUIs on commercial
versions of UNIX.
• Open source projects such as K Desktop Environment (KDE) and the GNOME desktop by the GNU
project. Both KDE and GNOME desktops run on Linux.
• Many UNIX users prefer command line interfaces and most windows users use the windows GUI
environment and almost never use MS-DOS shell.
System Calls
System calls provide an interface to the services made available by an operating system.
• Illustrating how system calls are used: Writing a simple program to read data from one file and copy
them to another file.
• System call sequence to copy the contents of one file to another file
• Ask the user for the names of the two files. This requires a sequence of system calls, First to write a
prompting message on the screen and then read from the keyboard characters that define the two files.
• Once two file names are obtained the program must open the input file and create the output file. If
input file doesn't exist, then program prints a message on the console (system call) and then terminate
abnormally (another system call). Else the input file is opened (system call).
• If the input file exists, new output file must be created. If output file exists, then terminate the
program abnormally (system call). Else create the output file (system call).
• Now both files are set up, program enters a loop that reads from the input file (a system call) and
writes to the output file (another system call).
• Finally, after the entire file is copied, the program may close both files (another system call), write a
message to the console (one more system call), and finally terminate normally (the final system call).

Even simple programs make heavy use of the operating system.

• Application developers design programs according to an Application Programming Interface.


• System calls are accessed by programs via a high-level Application Programming Interface (API)
rather than direct system call use.
• Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems
(including all versions of UNIX, Linux and Mac OS X), and Java API for the Java virtual machine
(JVM).
• Functions that make up an API invoke the actual system calls on behalf of the application
programmer.
• One benefit of programming according to an API is program portability:
◦ A program designed according to an API can compile and run on any system that supports the same
API.
• Actual system calls are more detailed and difficult to work with than the API
• The run-time support system for most programming languages provides a system-call interface that
serves as a link to the system calls made available by the OS.

System Call Implementation

• Typically, a number associated with each system call


◦ System-call interface maintains a table indexed according to these numbers.
• The system call interface invokes the 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
◦ Just needs to obey API and understand what OS will do as a result of execution of that system call.
◦ Most details of OS interface hidden from programmer by API, Managed by run-time support library.

API – System Call – OS Relationship


Figure 2.6 The handling of a user application invoking the open() system call
System Call Parameter Passing
Three general methods used to pass parameters to OS are –
• To pass parameters in registers
• If parameters are large blocks, address of block (where parameters are stored in memory) is
sent to OS in the register. (Linux & Solaris).
• Parameters can be pushed onto the stack by program and popped off the stack by OS.

Types of System Calls


The system calls can be categorized into six major categories:
• Process Control
• File management
• Device management
• Information management
• Communications
• Protection

Process control
• create process, terminate process
• end, abort – A running program needs to be able to halt its execution either normally(end) or
abnormally(abort).
• load, execute – A process executing one program may want to load and execute another program.
This feature allows the command interpreter to execute a program as directed by, user command.
• get process attributes, set process attributes – Execution of new processes should be controlled. This
control requires the ability to determine and reset the attributes of a process.
• wait for time – After creating new processes, we may need to wait for them to finish their execution.
We may want to wait for a certain amount of time to pass (wait for time).
• wait event, signal event – We want to wait for a specific event to occur (wait event). The processes
should signal when that event has occurred (signal event).
• allocate and free memory Locks for managing access to shared data between processes.

File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes

We should be able to create and delete files. Once the file is created, we need to open it and use it. We
may also read, write or reposition. Finally we need to close the file.
File attributes include file name, file type, protection code and so on. Two system calls, get file
attribute and set file attribute are required to determine the values of various attributes and perhaps to
reset them.
Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
A process may need several resources to execute. A system with multiple users may require us to first
request the device, to ensure exclusive use of it. After we are finished with the device we release it.
These functions are similar to open and close system calls for files.
Similarity between I/O devices and files is so great that many operating systems don't differentiate
between them.

Information maintenance
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
System calls to return the current date and time, number of current users, the version number of the
operating system, amount of free memory or disk space and so on.

Communications
• In message passing model, communicating processes exchange messages with one another to
transfer information.
• Before communication can take place, a connection must be opened. The recipient process must give
its permission for communication to take place with an accept connection call.
• The source of the communication, known as the client and recipient known as a server, then
exchange messages by using read message and write message system calls.
• In Shared-memory model processes create and gain access to regions of memory owned by other
processes.
• Processes exchange the information by reading and writing to the shared area.
• Processes are responsible for ensuring that they are not writing to the same location simultaneously.
Protection
• Control access to resources
• Get and set permissions
• Allow and deny user access
Protection provides mechanisms for controlling access to the resources provided by a computer
system. Get and set permissions manipulate the permission settings of resources such as files and
disks. Allow user and deny user system calls specify whether particular user can or cannot be allowed
to access certain resources.

Standard C Library Example


C program invoking printf() library call, which calls write() system call

System Programs
• System programs provide a convenient environment for program development and execution. Some
of them are simply user interfaces to system calls; others are considerably more complex
• They can be divided into:

◦ File management
◦ Status information
◦ File modification
◦ Programming-language support
◦ Program loading and execution
◦ Communications
• Most users’ view of the operating system is defined by system programs, not the actual system calls.

• File management – These programs create, delete, copy, rename, print, dump, list, and generally
manipulate files and directories.
• Status information Some programs ask the system for info - date, time, amount of available
memory, disk space, number of users.
◦ Others provide detailed performance, logging, and debugging information. Typically, these programs
format and print the output to the terminal or other output devices
◦ Some systems implement a registry - used to store and retrieve configuration information
• File modification
◦ Text editors to create and modify the content of files
◦ Special commands to search contents of files or perform transformations of the text
• Programming-language support – Compilers, assemblers, debuggers and interpreters for common
programming languages.
• Program loading and execution- Once a program is assembled or compiled it must be loaded into
memory to be executed. Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders,
debugging systems for higher-level and machine language.
• Communications - Provide the mechanism for creating virtual connections among processes, users,
and computer systems
◦ Allow users to send messages to one another’s screens, browse web pages, send electronic-mail
messages, log in remotely, transfer files from one machine to another

Operating System Design and Implementation


Design Goals
• Start the design by defining goals and specifications.
• Design of the system will be affected by the choice of hardware, type of system:batch, time shared,
single user, multiuser, distributed, real time etc.
• User goals and System goals
◦ User goals – operating system should be convenient to use, easy to learn, reliable, safe, and fast.
◦ System goals – operating system should be easy to design, implement, and maintain, as well as
flexible, reliable, error-free, and efficient.
◦ All these requirements are vague and may be interpreted in multiple ways.
• Specifying and designing an operating system is a highly creative task. General principles have been
developed in the field of software engineering.

Mechanisms and Policies


• Important principle is the separation of policy from mechanism. Mechanism: Determines how to do
something Policy: Determines What will be done
• Policies are likely to change across places or over time. In the worst case each change in policy
would require a change in the mechanism.
• Mechanism insensitive to changes in policy would be more desirable.
• Consider the 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.

Implementation
• Traditionally operating systems have been written in assembly language.
• However now they are most commonly written in higher-level languages such as C or C++.
• Advantages of using a higher level language: code can be written faster, is more compact and is
easier to understand and debug.
• Operating system can be easily ported to some other hardware – if written in higher-level language.
• Disadvantages of using a higher level language: reduced speed and increased storage requirements.
• Although OS is large, only a small amount of code is critical to high performance. Memory manager
and CPU scheduler are probably the most critical routines.
• Bottleneck routines can be identified and can be replaced with assembly-language equivalents.
Operating System Structure
• General-purpose OS is very large and complex program, it must be engineered carefully if it is to
function properly and be modified easily.
• A common approach is to partition the task into small components rather than have one monolithic
system.
• Each component should be well defined portion of the system, with carefully defined inputs, outputs
and functions.
• We discuss how these components are interconnected and melded into a kernel.

Simple Structure -- MS-DOS


• MS-DOS – written to provide the most functionality in the least space. It was not divided into
modules
• Although MS-DOS has some structure, its interfaces and levels of functionality are not well
separated.
◦ Application programs are able to access the basic I/O routines to write directly to display and disk
drives.
◦ Such freedom leaves MS-DOS vulnerable to errors in user programs, entire system may crash when
user program fails.

S-DOS Layer Structure


Non Simple Structure -- UNIX

• UNIX –initially limited by hardware functionality, the original UNIX operating system had limited
structuring. The UNIX OS consists of two separable parts
◦ Systems programs
◦ 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 through system calls.
• A large number of functions to be combined into one level. This monolithic structure was difficult to
implement and maintain.
• Beyond simple but not fully layered

Traditional UNIX System Structure

Figure 2.13 UNIX System Structure

Layered Approach

• A system can be modular in many ways. One method is the 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 layers are selected such that each uses functions (operations) and services of only lower-
level layers.
• This approach simplifies debugging and system verification.

Figure 2.14 A layered Operating System

First layer can be debugged without any concern for the rest of the system, because it uses only the
basic hardware.
• Once first layer is debugged its correct functioning can be assumed while second layer is debugged.
• An error found during debugging of a layer must be on that layer, because the layers below it are
already debugged. Thus design and implementation of the system are simplified.
• Each layer is implemented with only those operations provided by lower level layers.
• The major difficulty with the layered approach involves appropriately defining the various layers.
• Layered implementations tend to be less efficient than other types.
◦ For instance, user request for an I/O operation needs to pass through many layers before reaching the
hardware.
◦ Each layer adds overhead to the system call, the net result is a system call than takes longer than than
the one on a non-layered system.
Microkernel System Structure
• This method structures the operating system by removing all nonessential components from the
kernel and implementing them as system and user level programs. The result is smaller kernel.
• Microkernels provide minimal process and memory management, in addition to communication
facility.
• Microkernel provides communication facility between the client programs and various services that
are also in user space.
• Client and service communicate indirectly by exchanging messages with the microkernel.

• Benefits:
◦ Easier to extend a microkernel
◦ Easier to port the operating system to new architectures
◦ More reliable and secure(less code is running in kernel mode)
• Due to increased system function overhead, microkernel can suffer from performance decreases.

Modules
• Kernel has a set of core components and links in additional services either during boot time or
during run time.
• This strategy uses dynamically loadable modules and is common in modern implementations of
UNIX including Linux and Mac OS X.
• Solaris OS organized around a core kernel with seven types of loadable kernel modules.
• This design allows kernel to provide core services yet allows certain features to be implemented
dynamically.

Figure 2.15 Solaris loadable modules

• The approach resembles a layered system in that each kernel section has defined, protected
interfaces; But more flexible than layered system because any module can call any other module.
• The approach resembles microkernel in that primary module has only core functions and knows how
to load other modules; But more efficient than microkernel because message passing is not required to
communicate.
• Most modern operating systems are actually not one pure model.
• Hybrid combines multiple approaches to address performance, security, usability needs.

Virtual Machines

• Different classes of users need different kinds of user service. Hence running a single OS on a
computer system can disappoint many users.
• This problem is solved by using a virtual machine operating system(VM OS) to control the computer
system.
• The VM OS creates several virtual machines. Virtual machine abstracts the hardware of a single
computer into several different execution environments.
• User can use any OS of his choice on the virtual machine and run his programs under this OS.
• This way users of the computer system can use different operating systems at the same time. Single
physical machine can run multiple operating systems concurrently.
• Each of these operating systems a guest OS and call the virtual machine OS the host OS.

Figure 2.17 System modes. (A) Nonvirtual machine (b) Virtual machine

Benefits
• Being able to share the same hardware yet run several different operating systems concurrently.
• Since each virtual machine is completely isolated from all other virtual machines, there are no
protection problems.
• A virus inside a guest OS might damage that OS but is unlikely to affect the host or the other guests.
• A virtual machine system is perfect vehicle for operating system research and development. All
changes to the operating system need to be tested carefully to avoid all possible errors.
• System programmers are given their own virtual machine, and system development is done on the
virtual machine instead of on a physical machine.
• So no need of stopping the current system while changes are made and tested.
• Virtual machines allow for rapid porting and testing of programs in varying environments.
• Quality assurance engineers can test their applications in multiple environments without maintaining
a computer for each environment.

Implementation
• The VM OS achieves concurrent operation of guest operating systems through an action that
resembles process scheduling.
• VM OS selects a virtual machine and arranges to let the guest OS running on it execute its
instructions on the CPU.
• A guest OS remains in control of the host machine until the VM OS decides to switch to another
virtual machine.
• Dual mode of CPU causes some difficulties in the use of a VM OS. The VM OS must protect itself
from guest OSs, so it must run guest OSs with the CPU in the user mode.
• This makes guest OS vulnerable to corruption by a user process.
• With hardware support for several execution modes of the CPU. Host OS can run with the CPU in
the kernel mode, Guest OS processes are executed in user mode and guest OS runs with the CPU in
one of the intermediate modes.
• Full virtualization implies that the host machine and virtual machine have the same capabilities.
Hence OS can operate identically while running on a bare machine and on a virtual machine.

Para-virtualization
• Instead of making guest operating system to believe that it has a system to itself, Para-virtualization
presents the guest with a system that is similar but not identical to the guest's preferred system.
• Security issue in full virtualization could be resolved through paravirtualization.
• The privileged instructions would not be included in a virtual machine. Special instruction is
provided for use by a guest OS that wished to execute a privileged instruction.
• The Special instruction would cause a software interrupt and VM OS would execute the specialized
instruction on behalf of the guest OS.
• The host OS would know whether the special instruction in the virtual machine was used by a guest
OS or by a user process- latter is illegal.

VMware

• There are some methods which involve writing virtualization tool to run in user mode as an
application on top of the operating system.
• Virtual machines running within this tool believe they are running on bare hardware but in fact are
running inside a user level application.
• VMware workstation runs as an application on a host operating system such as Windows or Linux
and allows host system to run several different guest OSs.
• Each virtual machine has its own virtual CPU, memory, disk drives, network interfaces and so on.
• The physical disk guest owns and manages is really just a file within the file system of the host
operating system.
• In the scenario below Linux is running as the host OS and FreeBSD, Windows NT and Windows XP
are running as the guest OSs.

Figure 2.19 VMware architecture

The Java Virtual Machine


• Java is a popular object-oriented programming language. A Java program consists of one or more
classes.
• For each Java class, the compiler produces an architecture-neutral byte code output that will run on
any implementation of JVM.
• The JVM is a specification for an abstract computer. It consists of a class loader and a Java
interpreter.
• The class loader loads the compiled .class files from both the Java program and the Java API for
execution by the Java Interpreter.
• After the class is loaded, the verifier checks that the .class file is valid Java byte code, If the class
passes verification it is run by the Java interpreter.

Figure 2.20 The JVM


Operating-System Generation
• Operating system is designed for one machine at one site; the system must be configured or
generated for each specific computer site.
• SYSGEN program obtains information concerning the specific configuration of the hardware
system.
1. What CPU is to be used ? What options are installed
2. How much memory available
3. What devices are available
4. What operating system options are desired ?

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 memory, and starts its execution.
• Sometimes a two-step process in which a simple bootstrap loader fetches a more complex boot
program from the disk, which in turn loads the kernel.
• When system is powered up or rebooted – execution starts at a fixed memory location. ◦ At that
location initial bootstrap program resides. The program is in ROM.
• Bootstrap program initializes all aspects of the system from CPU registers to device controllers and
the contents of main memory.
• Storing the OS in ROM is suitable for small operating systems. A problem with ROM is that
executing code there is slower than executing code in RAM.
• For large Operating systems, bootstrap loader is stored in ROM and operating system is on the disk.

Processes Concept
• A process is a program under execution.
• Its current activity is indicated by PC(Program Counter) and CPU registers.
The Process Process memory is divided into four sections as shown in the figure below:
• The stack is used to store local variables, function parameters, function return values, return
address etc.
• The heap is used for dynamic memory allocation.
• The data section stores global and static variables.
• The text section comprises the compiled program code.
• Note that, there is a free space between the stack and the heap. When the stack is full, it grows
downwards and when the heap is full, it grows upwards.

Process State
A Process has 5 states. Each process may be in one of the following states –
• New - The process is in the stage of being created.
• Ready - The process has all the resources it needs to run. It is waiting to be assigned to the
processor.
• Running – Instructions are being executed..
• Waiting - The process is waiting for some event to occur. For example the process may be waiting
for keyboard input, disk access request, inter-process messages, a timer to go off, or a child process to
finish.
• Terminated - The process has completed its execution.

Process Control Block


For each process there is a Process Control Block (PCB), which stores the process-specific
information as shown below –

Process State – The state of the process may be new, ready, running, waiting, and so on.
Program counter – The counter indicates the address of the next instruction 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. Along with
the program counter, this state information must be saved when an interrupt occurs, to allow the
process to be continued correctly afterward.
CPU scheduling information- This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters.
Memory-management information – This include information such as the value of the base and
limit registers, the page tables, or the segment tables.
Accounting information – This information includes the amount of CPU and real time used, time
limits, account numbers, job or process numbers, and so on.
I/O status information – This information includes the list of I/O devices allocated to the process, a
list of open files, and so on.

Threads
• The process model discussed so far has implied that a process is a program that performs a
single thread of execution.
• Single thread of control allows the process to perform only one task at a time.
• For example, the user cannot simultaneously type in characters and run the spell checker within
the same process.
• Multiple threads of execution allows a process to perform more than one task at a time.
• But PCB must be expanded to include information for each thread.

Process Scheduling
Process Scheduler selects an available process for program execution on the CPU. In a multiprocessor
system - one process will be under execution and the rest of the processes have to wait until the CPU
is free and can be rescheduled.
The main objective of process scheduling is to keep the CPU busy at all times.

Scheduling Queues
• All processes admitted to the system are stored in the job queue.
• Processes in main memory and ready to execute are placed in the ready queue.
• Processes waiting for a device to become available are placed in device queues. There is
generally a separate device queue for each device.

Ready Queue And Various I/O Device Queues


These queues are generally stored as a linked list of PCBs. A queue header will contain two pointers -
the head pointer pointing to the first PCB and the tail pointer pointing to the last PCB in the list. Each
PCB has a pointer field that points to the next process in the queue.

Queueing diagram
A common representation of process scheduling is a queueing diagram. Each rectangular box in the
diagram 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, and the arrows indicate the flow of
processes in the system.
A new process is initially put in the ready queue. It waits in the ready queue until it is selected for
execution and is given the CPU. 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 subprocess and wait for its 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.

Schedulers
Selection of processes from various queues for scheduling purpose is carried out by the appropriate
scheduler. Often more processes are submitted than can be executed immediately. These processes are
kept in a job pool in mass-storage device for later execution.
• Long-term scheduler (or job scheduler) – selects processes from job pool and loads them into
memory for execution. i.e., selects which processes should be brought into the ready queue.
• Short-term scheduler (or CPU scheduler) – selects from among the processes that are ready
to execute and allocates the CPU to one of them. i.e., selects which process from the ready
queue should be executed next.
• The long-term scheduler controls the degree of multiprogramming(the number of processes in
memory).

• Processes can be described as either:


I/O-bound process – one that spends more of its time doing I/O than it spends doing computations.
CPU-bound process – generates I/O requests infrequently, using more of its time doing computations.
• Long-term scheduler must select a good process mix of I/O-bound and CPU-bound processes
for best performance.
• If the scheduler selects more I/O bound process, then I/O queue will be full and ready queue will be
empty.
Time sharing systems employ a medium-term scheduler. It swaps out the process from ready queue
and swap in the process to ready queue. When system loads get high, this scheduler will swap one or
more processes out of the ready queue for a few seconds, in order to allow smaller faster jobs to finish
up quickly and clear the system.
Advantages of medium-term scheduler –
• To remove process from memory and thus reduce the degree of multiprogramming
(number of processes in memory).
• To make a proper mix of processes(CPU bound and I/O bound )

Context Switch
The task of switching a CPU from one process to another process is called context switching.
Context-switch times are highly dependent on hardware support (Number of CPU registers).
• Interrupts cause the OS to change a CPU from its current task and to run a kernel routine.
• When an interrupt occurs, the system needs to save the current context of the process running on
the CPU, so context can be restored later.
• Context of a process is represented in the PCB, it includes the value of the CPU registers, the
process state and memory management information.
• Switching the CPU to another process requires performing a and a state restore of a different
process. This task is known as state save of the current process context switch.
• 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.
Context switch times are dependent on hardware support.
Operations on Processes

Process Creation
A process may create several new processes. The creating process is called a parent process, and the
new processes are called the children of that process. Each of these new processes may in turn create
other processes. Every process has a unique process ID.
A process will need certain resources (CPU time, memory, files, I/O devices) to accomplish its task.
When a process creates a subprocess, the subprocess may be able to obtain its resources in two ways :
• Directly from the operating system
• Subprocess may take the resources of the parent process.
The resource can be taken from parent in two ways –
o The parent may have to partition its resources among its children
o Share the resources among several children.
There are two options for the parent process after creating the child:
• Wait for the child process to terminate and then continue execution. The parent makes a wait( )
system call.
• Run concurrently with the child, continuing to execute without waiting.
Two possibilities for the address space of the child relative to the parent:
• The child may be an exact duplicate of the parent, sharing the same program and data segments in
memory. Each will have their own PCB, including program counter, registers, and PID. This is the
behaviour of the fork system call in UNIX.
• The child process may have a new program loaded into its address space, with all new code and
data segments. This is the behaviour of the spawn system calls in Windows.
In UNIX OS, a child process can be created by fork() system call. The fork system call, if successful,
returns the PID of the child process to its parents and returns a zero to the child process. If failure, it
returns -1 to the parent. Process IDs of current process or its direct parent can be accessed using the
getpid( ) and getppid( ) system calls respectively.
The parent waits for the child process to complete with the wait() system call. When the child process
completes, the parent process resumes and completes its execution.
In windows the child process is created using the function createprocess( ). The createprocess( )
returns 1, if the child is created and returns 0, if the child is not created.
Process Termination
A process terminates when it finishes executing its last statement and asks the operating system to
delete it, by using the exit( ) system call. All of the resources assigned to the process like memory,
open files, and I/O buffers, are deallocated by the operating system.
A process can cause the termination of another process by using abort() system call. The parent
process can terminate its child processes by knowing of the PID of the child.
A parent may terminate the execution of children for a variety of reasons, such as:
• The child has exceeded its usage of the resources, it has been allocated.
• The task assigned to the child is no longer required.
• The parent is exiting, and the operating system terminates all the children. This is called
cascading termination

Interprocess Communication
Processes executing may be either co-operative or independent processes.
• Independent Processes – processes that cannot affect other processes or be affected by other
processes executing in the system.
• Cooperating Processes – processes that can affect other processes or be affected by other
processes executing in the system.
Co-operation among processes are allowed for following reasons –
• Information Sharing - There may be several processes which need to access the same file. So the
information must be accessible at the same time to all users.
• Computation speedup - Often a solution to a problem can be solved faster if the problem can be
broken down into sub-tasks, which are solved simultaneously ( particularly when multiple
processors are involved. )
• Modularity - A system can be divided into cooperating modules and executed by sending
information among one another.
• Convenience - Even a single user can work on multiple task by information sharing.

Cooperating processes require some type of inter-process communication. This is allowed by two
models :
1) Shared Memory systems
2)Message Passing systems.
• Shared Memory is faster once it is set up, because no system calls are required and access
occurs at normal memory speeds. Shared memory is generally preferable when large
amounts of information must be shared quickly on the same computer.
• Message Passing requires system calls for every message transfer, and is therefore slower, but
it is simpler to set up and works well across multiple computers. Message passing is generally
preferable when the amount and/or frequency of data transfers is small.

Shared-Memory Systems

• A region of shared-memory is created within the address space of a process, which needs to
communicate. Other processes that needs to communicate uses this shared memory.
• The form of data and position of creating shared memory area is decided by the process.
Generally a few messages must be passed back and forth between the cooperating processes
first in order to set up and coordinate the shared memory access.
• The process should take care that the two processes will not write the data to the shared
memory at the same time.
Producer-Consumer Example Using Shared Memory
• This is a classic example, in which one process is producing data and another process is
consuming the data.
• The data is passed via an intermediary buffer (shared memory). The producer puts the data to
the buffer and the consumer takes out the data from the buffer.
• 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. In this situation, the consumer must wait until
an item is produced

There are two types of buffers into which information can be put –
• Unbounded buffer
• Bounded buffer
Unbounded buffer - There is no limit on the size of the buffer, and so on the data produced by
producer. But the consumer may have to wait for new items.
Bounded-buffer – As the buffer size is fixed. The producer has to wait if the buffer is full and the
consumer has to wait if the buffer is empty.
This example uses shared memory as a circular queue. The in and out are two pointers to the array.
Note in the code below that only the producer changes "in", and only the consumer changes "out".
• First the following data is set up in the shared memory area:

Bounded-Buffer – Producer
Bounded Buffer – Consumer

Message-Passing Systems
A mechanism to allow process communication without sharing address space. It is used in
distributed systems.
• Message passing systems uses system calls for "send message" and "receive message".
• A communication link must be established between the cooperating processes before messages
can be sent.
There are three methods of creating the link between the sender and the receiver-
• Direct or indirect communication ( naming )
• Synchronous or asynchronous communication (Synchronization)
• Automatic or explicit buffering.
a)Naming
The processes that wants to communicate should have a way to refer eachother. ( using some identity)
Direct communication the sender and receiver must explicitly know each others name. The syntax for
send() and receive() functions are as follows-
send (P, message) – send a message to process P
receive(Q, message) – receive a message from process Q
Properties of communication link :
• A link is established automatically between every pair of processes that wants to communicate.
The processes need to know only each other's identity to communicate.
• A link is associated with exactly one pair of communicating processes
• Between each pair, there exists exactly one link.
Disadvantages of direct communication – any changes in the identifier of a process, may have to
change the identifier in the whole system(sender and receiver), where the messages are sent and
received.
Indirect communication uses shared mailboxes, or ports.
A mailbox or port is used to send and receive messages. Mailbox is an object into which messages can
be sent and received. It has a unique ID. Using this identifier messages are sent and received.
Two processes can communicate only if they have a shared mailbox.
The send and receive functions are –
send(A, message) – send a message to mailbox A
receive(A, message) – receive a message from mailbox A
Properties of communication link:
• A link is established between a pair of processes only if they have a shared mailbox
• A link may be associated with more than two processes
• Between each pair of communicating processes, there may be any number of links, each link is
associated with one mailbox.
A mail box can be owned by the operating system. It must take steps to –
create a new mailbox
send and receive messages from mailbox
delete mailboxes.
b) Synchronization
The send and receive messages can be implemented as either blocking or non-blocking
• Blocking (synchronous) send - sending process is blocked (waits) until the message is
received by receiving process or the mailbox.
• Non-blocking (asynchronous) send - sends the message and continues (doesnot wait)
• Blocking (synchronous) receive - The receiving process is blocked until a message is
available
• Non-blocking (asynchronous) receive - receives the message without block. The received
message may be a valid message or null.
• Blocking send and receive provide a solution to the producer-consumer problem. The producer
invokes the blocking send( ) call and waits until the message is delivered either to the mailbox
or to the receiver. Consumer invokes blocking receive( ) and it is blocked until a message is
available.

c) Buffering
when messages are passed, a temporary queue is created. Such queue can be of three capacities:
• Zero capacity – The buffer size is zero (buffer does not exist). Messages are not stored in the
queue. The senders must block until receivers accept the messages.
• Bounded capacity- The queue is of fixed size(n). Senders must block if the queue is full. After
sending ‘n’ bytes the sender is blocked.
• Unbounded capacity - The queue is of infinite capacity. The sender never blocks.

You might also like