0% found this document useful (0 votes)
10 views

Module 1

Operating System module 1

Uploaded by

Lalli Krishnan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Module 1

Operating System module 1

Uploaded by

Lalli Krishnan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Operating Systems

5CS1009

Operating System Concepts – 9th Edit9on Silberschatz, Galvin and Gagne ©2013
Module 1: Operating Systems
overview

Operating System Concepts – 9th Edit9on Silberschatz, Galvin and Gagne ©2013
What is an Operating System?

A program that acts as an intermediary between a user of a


computer and the computer hardware.
It manages and control hardware and software.
OS provide platform for application software.
Operating system goals:
Execute user programs and make solving user problems
easier.
Make the computer system convenient to use.
Use the computer hardware in an efficient manner.

Operating System Concepts – 9th Edition 1.3 Silberschatz, Galvin and Gagne ©2013
Computer System Structure

Computer system can be divided into 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

Operating System Concepts – 9th Edition 1.4 Silberschatz, Galvin and Gagne ©2013
Four Components of a Computer System

Operating System Concepts – 9th Edition 1.5 Silberschatz, Galvin and Gagne ©2013
Two views of OS

Operating System can be viewed from two viewpoints

❑ User View

❑ System View

Operating System Concepts – 9th Edition 1.6 Silberschatz, Galvin and Gagne ©2013
User View
The user’s view of the operating system depends on the type of user
If the user is using standalone system,
▪ OS is designed for ease of use and high performances.
▪ Here resource utilization is not given importance.
If the users are at different terminals connected to a mainframe or
minicomputers, by sharing information and resources,
▪ 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 CPU moves data from/to main memory to/from local buffers.
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).
Users of hand-held systems, expects the OS to be designed for ease of
use and performance per amount of battery life.
Operating System Concepts – 9th Edition 1.7 Silberschatz, Galvin and Gagne ©2013
System View

OS is a resource allocator
Manages all resources
Decides between conflicting requests for efficient and
fair resource use
OS is a control program
Controls execution of programs to prevent errors and
improper use of the computer

Operating System Concepts – 9th Edition 1.8 Silberschatz, Galvin and Gagne ©2013
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

Operating System Concepts – 9th Edition 1.9 Silberschatz, Galvin and Gagne ©2013
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

Operating System Concepts – 9th Edition 1.10 Silberschatz, Galvin and Gagne ©2013
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:
Separate segments of code determine what action should
be taken for each type of interrupt

Operating System Concepts – 9th Edition 1.11 Silberschatz, Galvin and Gagne ©2013
Interrupt Timeline

Operating System Concepts – 9th Edition 1.12 Silberschatz, Galvin and Gagne ©2013
Bootstrap

When system is switched on, ‘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).
It initializes the CPU registers, memory, device controllers and other
initial setups.
The program also locates and loads, the OS kernel to the memory.
Then the OS starts with the first process to be executed (ie. ‘init’ process)
and then wait for the interrupt from the user

Operating System Concepts – 9th Edition 1.13 Silberschatz, Galvin and Gagne ©2013
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
A subset of total jobs in system is kept in memory
One job selected and run via job scheduling
When it has to wait (for I/O for example), OS switches to another job

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
Response time should be < 1 second
Each user has at least one program executing in memory process
If several jobs ready to run at the same time  CPU scheduling
If processes don’t fit in memory, swapping moves them in and out to run
Virtual memory allows execution of processes not completely in memory

Operating System Concepts – 9th Edition 1.14 Silberschatz, Galvin and Gagne ©2013
Types of Operating Systems Structures
• Simple/Monolithic Structure
• Micro-Kernel Structure
• Layered Structure
• Modular Structure

Operating System Concepts – 9th Edition 1.15 Silberschatz, Galvin and Gagne ©2013
Simple/Monolithic Structure
Such operating systems do not have well-defined structures and are small,
simple, and limited.
The interfaces and levels of functionality are not well separated.
MS-DOS is an example of such an operating system.
These types of operating systems cause the entire system to crash if one of
the user programs fails.

Operating System Concepts – 9th Edition 1.16 Silberschatz, Galvin and Gagne ©2013
Contd…
Advantages of Simple/Monolithic Structure
• It delivers better application performance because of the few interfaces
between the application program and the hardware.
• It is easy for kernel developers to develop such an operating system.
Disadvantages of Simple/Monolithic Structure
• The structure is very complicated, as no clear boundaries exist between
modules.
• It does not enforce data hiding in the operating system.

Operating System Concepts – 9th Edition 1.17 Silberschatz, Galvin and Gagne ©2013
Micro-Kernel Structure
This structure designs the operating system by removing all non-
essential components from the kernel and implementing them as
system and user programs.
This results in a smaller kernel called the micro-kernel. Advantages
of this structure are that all new services need to be added to user
space and does not require the kernel to be modified.
Thus it is more secure and reliable as if a service fails, then rest of
the operating system remains untouched. Mac OS is an example of
this type of OS.
Advantages of Micro-kernel Structure
• It makes the operating system portable to various platforms.
• As microkernels are small so these can be tested effectively.
Disadvantages of Micro-kernel Structure
• Increased level of inter module communication degrades system
performance.

Operating System Concepts – 9th Edition 1.18 Silberschatz, Galvin and Gagne ©2013
Layered Structure
OS is broken into a number of layers (levels).
The bottom layer (layer 0) is the hardware, and the topmost layer (layer N) is
the user interface.
These layers are so designed that each layer uses the functions of the lower-
level layers.
This simplifies the debugging process, if lower-level layers are debugged and
an error occurs during debugging, then the error must be on that layer only,
as the lower-level layers have already been debugged.
Advantages of Layered Structure
• Layering makes it easier to enhance the operating system, as the
implementation of a layer can be changed easily without affecting the other
layers.
• It is very easy to perform debugging and system verification.
Disadvantages of Layered Structure
• In this structure, the application’s performance is degraded as compared to
simple structure.
• It requires careful planning for designing the layers, as the higher layers use
the functionalities
Operating System Concepts – 9 Edition of only the lower
th 1.19 layers. Silberschatz, Galvin and Gagne ©2013
Contd..

Operating System Concepts – 9th Edition 1.20 Silberschatz, Galvin and Gagne ©2013
Modular Structure

Operating System Concepts – 9th Edition 1.21 Silberschatz, Galvin and Gagne ©2013
Contd..

It is considered as the best approach for an OS. It involves designing


of a modular kernel.
The kernel has only a set of core components and other services are
added as dynamically loadable modules to the kernel either during
runtime or boot time.
It resembles layered structure due to the fact that each kernel has
defined and protected interfaces, but it is more flexible than a
layered structure as a module can call any other module.

Operating System Concepts – 9th Edition 1.22 Silberschatz, Galvin and Gagne ©2013
Operating System Operations

Figure represent Transition from user to kernel mode

Operating System Concepts – 9th Edition 1.23 Silberschatz, Galvin and Gagne ©2013
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.

Operating System Concepts – 9th Edition 1.24 Silberschatz, Galvin and Gagne ©2013
Contd..
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

Operating System Concepts – 9th Edition 1.25 Silberschatz, Galvin and Gagne ©2013
Memory Management

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.

Operating System Concepts – 9th Edition 1.26 Silberschatz, Galvin and Gagne ©2013
Storage Management

There are three types of storage management


i) File system management
ii) Mass-storage management
iii) Cache management.

Operating System Concepts – 9th Edition 1.27 Silberschatz, Galvin and Gagne ©2013
File system management
A file is a collection of related information defined by its creator.
files represent programs and data.
Data files may be numeric, alphabetic, alphanumeric, or binary.
Files may be free-form (for example, text files).
The operating system implements the abstract concept of a file by managing mass
storage media.
Files are normally organized into directories to make them easier to use.
When multiple users have access to files, it may be desirable to control by whom and
in what ways (read, write, execute) files may be accessed.
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
Operating System Concepts – 9th Edition 1.28 Silberschatz, Galvin and Gagne ©2013
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.
Most modern computer systems use disks as the storage medium for both programs
and data.
The operating system is responsible for the following activities in connection with
disk management:
• Free-space management
• Storage allocation
• Disk scheduling

As the secondary storage is used frequently, it must be used efficiently. The


entire speed of operation of a computer may depend on the speeds of the disk. Magnetic
tape drives and their tapes, CD, DVD drives and platters are tertiary storage devices

Operating System Concepts – 9th Edition 1.29 Silberschatz, Galvin and Gagne ©2013
Cach Management
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.
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.
data transfer from cache to CPU and registers is usually a hardware function, with no
operating-system intervention. In contrast, transfer of data from disk to memory is
usually controlled by the operatin.g system

Operating System Concepts – 9th Edition 1.30 Silberschatz, Galvin and Gagne ©2013
Contd..
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.

Operating System Concepts – 9th Edition 1.31 Silberschatz, Galvin and Gagne ©2013
Storage-Device Hierarchy

Operating System Concepts – 9th Edition 1.32 Silberschatz, Galvin and Gagne ©2013
Protection and Security
Protection is a mechanism for controlling the access of processes or users to the
resources defined by a computer system.
Protection improves reliability.
A protection-oriented system provides a means to distinguish between authorized and
unauthorized usage. A
system can have adequate protection but still be prone to failure and allow
inappropriate access.
Consider a user whose authentication information is stolen. Her data could be copied
or deleted, even though file and memory protection are working.
It is the job of security to defend a system from external and internal attacks. Such
attacks spread across a huge range and include viruses and worms, denial-of service
attacks etc.
Protection and security require the system to be able to distinguish among all its users.
Most operating systems maintain a list of usernames and associated user identifiers
(user IDs).
When a user logs in to the system, the authentication stage determines the appropriate
user ID for the user.

Operating System Concepts – 9th Edition 1.33 Silberschatz, Galvin and Gagne ©2013
Distributed Systems
A distributed system is a collection of systems that are networked to provide the users
with access to the various resources in the network.
Access to a shared resource increases computation speed, functionality, data
availability, and reliability.
A network is a communication path between two or more systems. Networks vary by
the protocols used(TCP/IP,UDP,FTP etc.), the distances between nodes, and the
transport media(copper wires, fiber-optic,wireless).
TCP/IP is the most common network protocol. The operating systems support of
protocols also varies. Most operating systems support TCP/IP, including the Windows
and UNIX operating systems.
Networks are characterized based on the distances between their nodes. A local-area
network (LAN) connects computers within a room, a floor, or a building. A wide-area
network (WAN) usually links buildings, cities, or countries. A global company may
have a WAN to connect its offices worldwide. These networks may run one protocol
or several protocols. A metropolitan-area network (MAN) connects buildings within a
city.

Operating System Concepts – 9th Edition 1.34 Silberschatz, Galvin and Gagne ©2013
Services of Operating System

• Program execution
• Input Output Operations
• Communication between Process
• File Management
• Memory Management
• Process Management
• Security and Privacy
• Resource Management
• User Interface
• Networking
• Error handling
• Time Management

Operating System Concepts – 9th Edition 1.35 Silberschatz, Galvin and Gagne ©2013
Operating System Services

Operating System Concepts – 9th Edition 1.36 Silberschatz, Galvin and Gagne ©2013
User Operating-System Interface

There are several ways for users to interface with the operating system

(i) Command-line interface, or command interpreter, allows users to


directly enter commands to be performed by the operating system.
(ii) Graphical user interface (GUI), allows users to interface with the
operating system using pointer device and menu system.

Operating System Concepts – 9th Edition 1.37 Silberschatz, Galvin and Gagne ©2013
Command-line interface

Command Interpreters are used to give commands to the OS. There are multiple
command interpreters known as shells.
The main function of the command interpreter is to get and execute the user-
specified command.
Many of the commands manipulate files: create, delete, list, print, copy, execute,
and so on.
The commands can be implemented in two general ways-
The command interpreter itself contains the code to execute the command. For
example, a command to delete a file may cause the command interpreter to
jump to a particular section of its code that sets up the parameters and makes
the appropriate system call.
The code to implement the command is in a function in a separate file. The
interpreter searches for the file and loads it into the memory and executes it by
passing the parameter.

Operating System Concepts – 9th Edition 1.38 Silberschatz, Galvin and Gagne ©2013
Graphical User Interfaces

A second strategy for interfacing with the operating system is through a


userfriendly graphical user interface or GUI. Rather than having users directly enter
commands via a command-line interface, a GUI allows provides a mouse-based
window-and-menu system as an interface.
A GUI provides a desktop metaphor where the mouse is moved to position its
pointer on images, or icons, on the screen (the desktop) that represent programs,
files, directories, and system functions.
Depending on the mouse pointer's location, clicking a button on the mouse can
invoke a program, select a file or directory—known as a folder— or pull down a
menu that contains commands.

Operating System Concepts – 9th Edition 1.39 Silberschatz, Galvin and Gagne ©2013
System Calls
System calls provides an interface to the services of the operating system. These are
generally written in C or C++, although some are written in assembly for optimal
performance.
The below figure illustrates the sequence of system calls required to copy a file
content from one file (input file) to another file (output file).

An example to illustrate how system calls are used: writing a simple program to
read data from one file and copy them to another file
Operating System Concepts – 9th Edition 1.40 Silberschatz, Galvin and Gagne ©2013
cont.
There are number of system calls used to finish this task. The first system call
is to write a message on the screen (monitor). Then to accept the input
filename. Then another system call to write message on the screen, then to
accept the output filename.
When the program tries to open the input file, it may find that there is no file
of that name or that the file is protected against access. In these cases, the
program should print a message on the console (another system call) and then
terminate abnormally (another system call) and create a new one (another
system call).
Now that both the files are opened, we enter a loop that reads from the input
file (another system call) and writes to 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 or window (system
call), and finally terminate normally (final system call).

Operating System Concepts – 9th Edition 1.41 Silberschatz, Galvin and Gagne ©2013
The handling of a user application invoking the open() system call

Operating System Concepts – 9th Edition 1.42 Silberschatz, Galvin and Gagne ©2013
cont.

Most programmers do not use the low-level system calls directly, but instead
use an "Application Programming Interface", API.
Instead of direct system calls provides for greater program portability
between different systems. The API then makes the appropriate system calls
through the system call interface, using a system call table to access specific
numbered system calls.
Each system call has a specific numbered system call. The system call table
(consisting of system call number and address of the particular service)
invokes a particular service routine for a specific system call.
The caller need know nothing about how the system call is implemented or
what it does during execution.

Operating System Concepts – 9th Edition 1.43 Silberschatz, Galvin and Gagne ©2013
Passing of parameters as a table

Operating System Concepts – 9th Edition 1.44 Silberschatz, Galvin and Gagne ©2013
cont.

Three general methods used to pass parameters to OS are –


i) To pass parameters in registers
ii) If parameters are large blocks, address of block (where parameters
are stored in memory) is sent to OS in the register. (Linux & Solaris).
iii) Parameters can be pushed onto the stack by program and popped
off the stack by OS.

Operating System Concepts – 9th Edition 1.45 Silberschatz, Galvin and Gagne ©2013
Types of System Calls

The system calls can be categorized into six major categories

1. Process Control
2. File management
3. Device management
4. Information management
5. Communications
6. Protection

Operating System Concepts – 9th Edition 1.46 Silberschatz, Galvin and Gagne ©2013
Types of system calls

Operating System Concepts – 9th Edition 1.47 Silberschatz, Galvin and Gagne ©2013
1. Process Control
A collection of programs that provide a convenient environment for program
Process control system calls include end, abort, load, execute, create process, terminate
process, get/set process attributes, wait for time or event, signal event, and allocate and
free memory.
Processes must be created, launched, monitored, paused, resumed, and eventually
stopped.
When one process pauses or stops, then another must be launched or resumed
Process attributes like process priority, max. allowable execution time etc. are set and
retrieved by OS.
After creating the new process, the parent process may have to wait (wait time) or wait
for an event to occur (wait event). The process sends back a signal when the event has
occurred (signal event).

Operating System Concepts – 9th Edition 1.48 Silberschatz, Galvin and Gagne ©2013
2. File Management
The file management functions of OS are –
File management system calls include create file, delete file,
open, close, read, write, reposition, get file attributes, and set
file attributes.
After creating a file, the file is opened. Data is read or
written to a file.
The file pointer may need to be repositioned to a point.
The file attributes like filename, file type, permissions, etc.
are set and retrieved using system calls.
These operations may also be supported for directories as well
as ordinary files.

Operating System Concepts – 9th Edition 1.49 Silberschatz, Galvin and Gagne ©2013
3. Device Management

Device management system calls include request device, release


device, read, write, reposition, get/set device attributes, and
logically attach or detach devices.
When a process needs a resource, a request for resource is done.
Then the control is granted to the process. If requested resource is
already attached to some other process, the requesting process has
to wait.
In multiprogramming systems, after a process uses the device, it
has to be returned to OS, so that another process can use the
device.
Devices may be physical (e.g. disk drives ), or virtual / abstract (
e.g. files, partitions, and RAM disks ).

Operating System Concepts – 9th Edition 1.50 Silberschatz, Galvin and Gagne ©2013
4. Information Maintenance

Information maintenance system calls include calls to get/set the


time, date, system data, and process, file, or device attributes.
These system calls care used to transfer the information between
user and the OS. Information like current time & date, no. of
current users, version no. of OS, amount of free memory, disk
space etc. are passed from OS to the user.

Operating System Concepts – 9th Edition 1.51 Silberschatz, Galvin and Gagne ©2013
5. Communication
Communication system calls create/delete communication connection, send/receive messages,
transfer status information, and attach/detach remote devices.
The message passing model must support calls to:
➢ Identify a remote process and/or host with which to communicate.
➢ Establish a connection between the two processes.
➢ Open and close the connection as needed.
➢ Transmit messages along the connection.
➢ Wait for incoming messages, in either a blocking or non-blocking state.
➢ Delete the connection when no longer needed.
The shared memory model must support calls to: o Create and access memory that is shared
amongst processes (and threads. )
Free up shared memory and/or dynamically allocate it as needed.
Message passing is simpler and easier, (particularly for inter-computer communications), and
is generally appropriate for small amounts of data. It is easy to implement, but there are
system calls for each read and write process.
Shared memory is faster,and is generally the better approach where large amounts of data are
to be shared. This model is difficult to implement, and it consists of only few system calls.
Operating System Concepts – 9th Edition 1.52 Silberschatz, Galvin and Gagne ©2013
6. Protection

Protection provides mechanisms for controlling which users / processes have access
to which system resources.
System calls allow the access mechanisms to be adjusted as needed, and for non-
privileged users to be granted elevated access permissions under carefully controlled
temporary circumstances.

Operating System Concepts – 9th Edition 1.53 Silberschatz, Galvin and Gagne ©2013
System Programs
A collection of programs that provide a convenient environment for program
development and execution (other than OS) are called system programs or system
utilities.
System programs may be divided into five categories :
1. File management - programs to create, delete, copy, rename, print, list, and generally
manipulate files and directories
2. Status information - Utilities to check on the date, time, number of users, processes
running, data logging, etc. System registries are used to store and recall configuration
information for particular applications.
3. File modification - e.g. text editors and other tools which can change file contents.
4. Programming-language support - E.g. Compilers, linkers, loaders, debuggers,
profilers, assemblers, library archive management, interpreters for common languages, and
support for make etc., as well as interactive debuggers.
5. Communications - Programs for providing connectivity between processes and users,
including mail, web browsers, remote logins, file transfers, and remote command execution

Operating System Concepts – 9th Edition 1.54 Silberschatz, Galvin and Gagne ©2013
Operating-System Design and Implementation
Design Goals
The first problem in designing a system is to define goals and specifications. At the
highest level, the design of the system will be affected by the choice of hardware and
the type of system: batch, time shared, single user, multiuser, distributed, real time, or
general purpose.
Beyond this highest design level, the requirements may be much harder to specify. The
requirements can, however, be divided into two basic groups
1. User goals (User requirements)
2. System goals (system requirements)

User requirements are the features that user care about and understand like system
should be convenient to use, easy to learn, reliable, safe and fast.
System requirements are written for the developers, ie. People who design the OS.
Their requirements are like easy to design, implement and maintain, flexible, reliable,
error free and efficient.

Operating System Concepts – 9th Edition 1.55 Silberschatz, Galvin and Gagne ©2013
Mechanisms and Policies

Policies determine what is to be done. Mechanisms determine how it is to be


implemented.
Example: in timer- counter and decrementing counter is the mechanism and deciding
how long the time has to be set is the policies.
Policies change overtime. In the worst case, each change in policy would require a
change in the underlying mechanism.
If properly separated and implemented, policy changes can be easily adjusted without
re- writing the code, just by adjusting parameters or possibly loading new data /
configuration files.

Operating System Concepts – 9th Edition 1.56 Silberschatz, Galvin and Gagne ©2013
Implementation

Traditionally OS were written in assembly language.


In recent years, OS are written in C, or C++. Critical sections of code are still written
in assembly language.
The first OS that was not written in assembly language, it was the Master Control
Program (MCP).
The advantages of using a higher-level language for implementing operating systems
are: The code can be written faster, more compact, easy to port to other systems and is
easier to understand and debug.
The only disadvantages of implementing an operating system in a higher-level
language are reduced speed and increased storage requirements

Operating System Concepts – 9th Edition 1.57 Silberschatz, Galvin and Gagne ©2013
Virtual Machines
Virtual machine allows user to open multiple OS in a computer, thereby creating the
illusion that each separate execution environment is running its own private computer.
Creates an illusion that a process has its own processor with its own memory.
Host OS is the main OS installed in system and the other OS installed in the system are
called guest OS

Figure: System modes. (A) Non-virtual machine (b) Virtual machine

Operating System Concepts – 9th Edition 1.58 Silberschatz, Galvin and Gagne ©2013
VM Implementation
The virtual-machine concept is useful, it is difficult to
implement.
Work is required to provide an exact duplicate of the
underlying machine. Remember that the underlying
machine has two modes: user mode and kernel mode.
The virtual-machine software can run in kernel mode,
since it is the operating system. The virtual machine
itself can execute in only user mode.

Operating System Concepts – 9th Edition 1.59 Silberschatz, Galvin and Gagne ©2013
Benefits
Able to share the same hardware and run several different execution environments
(OS).
Host system is protected from the virtual machines and the virtual machines are
protected from one another. A virus in guest OS, will corrupt that OS but will not affect
the other guest systems and host systems.
Even though the virtual machines are separated from one another, software resources
can be shared among them. Two ways of sharing s/w resource for communication are:
o To share a file system volume (part of memory).
o To develop a virtual communication network to communicate between the
virtual machines.
The operating system runs on and controls the entire machine. Therefore, the current
system must be stopped and taken out of use while changes are made and tested. This
period is commonly called system development time. In virtual machines such problem
is eliminated. User programs are executed in one virtual machine and system
development is done in another environment.
Multiple OS can be running on the developer’s system concurrently. This helps in
rapid porting and testing of programmer’s code in different environments.
System consolidation – two or more systems are made to run in a single system.
Operating System Concepts – 9th Edition 1.60 Silberschatz, Galvin and Gagne ©2013
VMware

VMware is a popular commercial application that abstracts Intel 80X86 hardware into
isolated virtual machines. The virtualization tool runs in the user-layer on top of the
host OS. The virtual machines running in this tool believe they are running on bare
hardware, but the fact is that it is running inside a user-level application.
VMware runs as an application on a host operating system such as Windows or Linux
and allows this host system to concurrently run several different guest operating
systems as independent virtual machines.
In below scenario, Linux is running as the host operating system; FreeBSD, Windows
NT, and Windows XP are running as guest operating systems. The virtualization layer
is the heart of VMware, as it abstracts the physical hardware into isolated virtual
machines running as guest operating systems. Each virtual machine has its own virtual
CPU, memory, disk drives, network interfaces, and so forth.

Operating System Concepts – 9th Edition 1.61 Silberschatz, Galvin and Gagne ©2013
VMware architecture

Operating System Concepts – 9th Edition 1.62 Silberschatz, Galvin and Gagne ©2013
The Java Virtual Machine

Java was designed from the beginning to be platform independent, by running


Java only on a Java Virtual Machine, JVM, of which different implementations
have been developed for numerous different underlying HW platforms.
Java source code is compiled into Java byte code in .class files. Java byte code
is binary instructions that will run on the JVM.
The JVM implements memory management and garbage collection.
JVM consists of class loader and Java Interpreter. Class loader loads compiled
.class files from both Java program and Java API for the execution of Java
interpreter. Then it checks the .class file for validity.

Operating System Concepts – 9th Edition 1.63 Silberschatz, Galvin and Gagne ©2013
The JVM

Operating System Concepts – 9th Edition 1.64 Silberschatz, Galvin and Gagne ©2013
Processes
A process is a program under execution.
Its current activity is indicated by PC (Program Counter) and the contents of the
processor's registers.
Process memory is divided into four sections as shown in the figure below:
• The stack is used to store temporary data such as local variables, function
parameters, function return values, return address etc.
• The heap which is memory that is dynamically allocated during process run time
• The data section stores global 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.

Operating System Concepts – 9th Edition 1.65 Silberschatz, Galvin and Gagne ©2013
Process in memory

Operating System Concepts – 9th Edition 1.66 Silberschatz, Galvin and Gagne ©2013
Process State
A Process has 5 states. Each process may be in one of the following
states –
1. New - The process is in the stage of being created.
2. Ready - The process has all the resources it needs to run. It is waiting to
be assigned to the processor.
3. Running – Instructions are being executed.
4. 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.
5. Terminated - The process has completed its execution

Operating System Concepts – 9th Edition 1.67 Silberschatz, Galvin and Gagne ©2013
Diagram of process state

Operating System Concepts – 9th Edition 1.68 Silberschatz, Galvin and Gagne ©2013
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 includes 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.
Operating System Concepts – 9th Edition 1.69 Silberschatz, Galvin and Gagne ©2013
Diagram of Process control block (PCB)
The PCB simply serves as the repository for any information that may
vary from process to process .

Operating System Concepts – 9th Edition 1.70 Silberschatz, Galvin and Gagne ©2013
Threads
Threads are the smallest unit of execution within a process and are fundamental for
achieving multitasking and parallelism.
It is a lightweight process that runs within a larger process or the OS itself.
There can be more than one thread inside a process.
Each thread of the same process makes use of a separate program counter and a stack
of activation records and control blocks.

Operating System Concepts – 9th Edition 1.71 Silberschatz, Galvin and Gagne ©2013
Thread States in Operating Systems
When a thread moves through the system, it is always in one of the five states:
Ready
Running
Waiting
Delayed
Blocked

In order to execute all the processes successfully, the processor needs to


maintain the information about each thread through Thread Control Blocks
(TCB).
Operating System Concepts – 9th Edition 1.72 Silberschatz, Galvin and Gagne ©2013
Contd..
1. When an application is to be processed, then it creates a thread.
2. It is then allocated the required resources(such as a network) and it comes in
the READY queue.
3. When the thread scheduler (like a process scheduler) assign the thread with
processor, it comes in RUNNING queue.
4. When the process needs some other event to be triggered, which is outsides
it’s control (like another process to be completed), it transitions
from RUNNING to WAITING queue.
5. When the application has the capability to delay the processing of the thread,
it when needed can delay the thread and put it to sleep for a specific amount
of time. The thread then transitions from RUNNING to DELAYED queue.An
example of delaying of thread is snoozing of an alarm. After it rings for the
first time and is not switched off by the user, it rings again after a specific
amount of time. During that time, the thread is put to sleep.
6. When thread generates an I/O request and cannot move further till it’s done, it
transitions from RUNNING to BLOCKED queue.
7. After the process is completed, the thread transitions
from RUNNING to FINISHED.
Operating System Concepts – 9th Edition 1.73 Silberschatz, Galvin and Gagne ©2013
Thread model
Types of thread model

•User Level Thread


•Kernel Level Thread

Operating System Concepts – 9th Edition 1.74 Silberschatz, Galvin and Gagne ©2013
User Level Threads
User Level Thread is a type of thread that is not created using system calls.
The kernel has no work in the management of user-level threads. User-level
threads can be easily implemented by the user.
Advantages of User-Level Threads
• Implementation of the User-Level Thread is easier than Kernel Level
Thread.
• Context Switch Time is less in User Level Thread.
• User-Level Thread is more efficient than Kernel-Level Thread.
Disadvantages of User-Level Threads
• There is a lack of coordination between Thread and Kernel.
• In case of a page fault, the whole process can be blocked.

Operating System Concepts – 9th Edition 1.75 Silberschatz, Galvin and Gagne ©2013
Kernel Level Threads
kernel Level Thread is a type of thread that can recognize the Operating
system easily.
Kernel Level Threads has its own thread table where it keeps track of the
system.
The operating System Kernel helps in managing threads.
Kernel Threads have somehow longer context switching time.
Kernel helps in the management of threads.
Advantages of Kernel-Level Threads
• It has up-to-date information on all threads.
• Applications that block frequency are to be handled by the Kernel-Level
Threads.
• Whenever any process requires more time to process, Kernel-Level
Thread provides more time to it.
Disadvantages of Kernel-Level threads
• Kernel-Level Thread is slower than User-Level Thread.
• Implementation of this type of thread is a little more complex than a user-
level thread.
Operating System Concepts – 9th Edition 1.76 Silberschatz, Galvin and Gagne ©2013
End of Chapter 1

Operating System Concepts – 9th Edit9on Silberschatz, Galvin and Gagne ©2013

You might also like