OS Introduction

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

EC416-Operating Systems

Dr. B. Hemantha Kumar


Professor,
Department of IT
RVR & JC College of Engineering
OPERATING SYSTEMS-Syllabus

UNIT I:
• Introduction: What Operating Systems Do, Operating-
System Structure, Operating-System Operations,
Process Management, Memory Management, Storage
Management, Protection and Security.
• Operating-System Structures: Operating-System
Services, User and Operating-System Interface, System
Calls, Types of System calls.
• Process Concept: Process Concept, Process Scheduling,
Operations on Processes, Inter process
Communication.

Dr.B.Hemantha Kumar. RVR&JC CE 2


OPERATING SYSTEMS-Syllabus

UNIT II:
• Multithreaded Programming: Overview of
Multithreading, Multithreading Models, Implicit
Threading.
• Process Scheduling: Basic Concepts, Scheduling
Criteria, Scheduling Algorithms, Thread
Scheduling, Multiple-Processor Scheduling.
• Synchronization: Background, The Critical-
Section Problem, Peterson’s solution,
Synchronization Hardware, Semaphores, Classic
Problems of Synchronization.
Dr.B.Hemantha Kumar. RVR&JC CE 3
OPERATING SYSTEMS-Syllabus

UNIT III:
• Dead Locks: System Model, Deadlock
Characterization, Methods for Handling
Deadlocks, Deadlock Prevention, Deadlock
Avoidance, Deadlock Detection, Recovery from
Deadlock
• Memory-Management Strategies: Background,
Swapping, Contiguous Memory Allocation,
Segmentation, Paging.
• Virtual-Memory Management: Background,
Demand Paging, Page Replacement algorithms.
Dr.B.Hemantha Kumar. RVR&JC CE 4
OPERATING SYSTEMS-Syllabus

UNIT IV:
• Files System: File Concept, Access Methods, Directory and
Disk Structure, File-System Mounting, File sharing,
Protection.
• Implementing File-Systems: File-System Structure, File-
System Implementation, Directory Implementation,
Allocation Methods, and Free-Space Management.
• Mass-Storage Structure: Overview of Mass-Storage
Structure, Disk Structure, Disk Scheduling.

TEXT BOOK:
• Operating System Concepts-Abraham Silberchatz, Peter B,
Galvin, Greg Gange 9th Edition, John Wiley.
Dr.B.Hemantha Kumar. RVR&JC CE 5
OVER VIEW OF OPERATING SYSTEM
Operating System: Operating system is a program
that acts as an intermediary between a user of a
computer and the computer hardware and also it
manages the entire computer system components
(hardware & 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
Dr.B.Hemantha Kumar. RVR&JC CE 6
OVER VIEW OF OPERATING SYSTEM
Functionality of computer is to execute user programs
Functionality of OS is to execute the computer system.
For example to execute the following simple program

#include <stdio.h>
main()
To execute this simple
{ int x,y,z; program in a
printf(“enter x, y values”);
scanf(“%d%d”, &x,&y);
computer what it
z=x+y; needs?
printf(“total= %d”, z);
}

Dr.B.Hemantha Kumar. RVR&JC CE 7


OVER VIEW OF OPERATING SYSTEM
Functionality of computer is to execute user programs
Functionality of OS is to execute the computer system.
For example to execute the following simple program
#include <stdio.h> To execute this simple program user needs:
main() Text editor (s/w) –to write the program
{ int x,y,z; Key Board(h/w) – to type the program
printf(“enter x, y values”); Monitor(h/w) – to display program, I/P & O/P
scanf(“%d%d”, &x,&y); Hard disk(h/w) – to store the program
z=x+y; permanently.
printf(“total= %d”, z); Compiler(s/w) – to compile the program
} Processor(h/w)- to execute the program(process)
Memory (h/w)- to store data (x,y&z) temporarily
OS(s/w)- to manage all these sw & hw resources.

Dr.B.Hemantha Kumar. RVR&JC CE 8


OVER VIEW OF OPERATING SYSTEM
Computer System Structure : Computer system can be divided into
four components
• Hardware – provides basic computing resources for the system.
– CPU, memory, I/O devices
• 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
• Operating system
– Controls and coordinates use of hardware among various applications
and users
• Users
– People, machines, other computers

Dr.B.Hemantha Kumar. RVR&JC CE 9


Components of computer system
User 1 User 2 User 3 ------- User n

Compiler Assembler Text Editor - - - - - - - Databse


System
System and Application Programs

Operating System

Computer Hardware

Components of computer system


Dr.B.Hemantha Kumar. RVR&JC CE 10
OVER VIEW OF OPERATING SYSTEM
Operating System Definition :
• Operating system is a program that acts as an intermediary
between a user of a computer and the computer hardware
• 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
Note: The one program running at all times on the computer is
the kernel(OS).
Dr.B.Hemantha Kumar. RVR&JC CE 11
OVER VIEW OF OPERATING SYSTEM
Computer Startup
• bootstrap program is loaded at power-up or reboot
• It is stored within the computer hardware in read-only
memory (ROM) or electrically erasable programmable read-
only memory (EEPROM), known by the general term
firmware.
• Initializes all aspects of system , from CPU registers to device
controllers to memory contents.
• The bootstrap program must know how to load the operating
system and how to start executing that system.
• That is bootstrap program must locate the operating-system
kernel and load it into memory.
Note: The one program running at all times on the computer is
the kernel(OS).
Dr.B.Hemantha Kumar. RVR&JC CE 12
OVER VIEW OF OPERATING SYSTEM
Functions of Operating System : Today most operating systems perform the
following important functions :
• Processor management : It manages the assignment of processor to different
tasks being performed by the computer system.
• Process management : It manages the execution of process according to their
priorities .
• Memory management : It manages the allocation of main memory and other
storage areas to the system programs as well as user programs and data.
• Input / Output management : It manages the co-ordination and assignment of
different Input and Output devices while one or more programs are executed.
• File management : It allows all files to be easily changed and modified through
the use of text editors or some other file manipulation routines.
• Establishment and enforcement of a priority system : It determines and
maintains the order in which jobs are to be executed in the computer system.
• Interpretation of commands and instructions.
• Facilitates easy communication between the computer system and the
computer operator. Dr.B.Hemantha Kumar. RVR&JC CE 13
Computer System Organization
• 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

A modern computer system.


Dr.B.Hemantha Kumar. RVR&JC CE 14
Computer System Organization
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
• I/O is from the device to local buffer of controller
• Device controller informs CPU that it has finished its operation by
causing An interrupt .
• Hardware may trigger an interrupt at any time by sending a signal
to the CPU, usually by way of the system bus.
• Software may trigger an interrupt by executing a special operation
called a system call

Dr.B.Hemantha Kumar. RVR&JC CE 15


Computer System Organization
Common Functions of Interrupts
• Interrupt transfers control to the interrupt service routine
generally, through the interrupt vector, which contains the
addresses of all the service routines
• Interrupt architecture must save the address of the interrupted
instruction
• Incoming interrupts are disabled while another interrupt is being
processed to prevent a lost interrupt.
• A trap is a software-generated interrupt caused either by an error
or a user request
• An operating system is interrupt driven

Dr.B.Hemantha Kumar. RVR&JC CE 16


Types of Operating System

• Batch operating system


• Multiprogramming Batch Systems
• Time-sharing operating systems(Multitasking
Systems)
• Multiprocessor Systems(Parallel Systems)
• Distributed operating System
• Real Time operating System

Dr.B.Hemantha Kumar. RVR&JC CE 17


Types of Operating System
Batch operating system:The users of batch operating system do not
interact with the computer directly.
Each user prepares his job on an offline device like punch cards and
submits it to the computer operator.
To speed up processing, jobs with similar needs are batched together
and run as a group.
Thus, the programmers left their programs with the operator. The
operator then sorts programs into batches with similar requirements.
The problems with Batch Systems are following:
Lack of interaction between the user and job.
CPU is often idle, because the speeds of the mechanical I/O devices is
slower than CPU.
Difficult to provide the desired priority.
Dr.B.Hemantha Kumar. RVR&JC CE 18
Types of Operating System
Multiprogramming Systems:
• In this the operating system picks up and begins to execute one of
the jobs from memory.
• Once this job needs an I/O operation operating system switches to
another job (CPU and OS always busy).
• Jobs in the memory are always less than the number of jobs on
disk(Job Pool).
• If several jobs are ready to run at the same time, then the system
chooses which one to run through the process of CPU Scheduling
• In Non-multiprogrammed system, there are moments when CPU
sits idle and does not do any work.
• In Multiprogramming system, CPU will never be idle and keeps on
processing.
Dr.B.Hemantha Kumar. RVR&JC CE 19
Types of Operating System
Multiprogramming Systems:
• In Multiprogramming system, CPU will never be idle and keeps on
processing.

Memory layout for a multiprogramming system.


Dr.B.Hemantha Kumar. RVR&JC CE 20
Types of Operating System
Time-sharing operating systems: Time sharing is a technique which
enables many people, located at various terminals, to use a particular
computer system at the same time.
Time-sharing or multitasking is a logical extension of
multiprogramming.
Processor's time which is shared among multiple users
simultaneously is termed as time-sharing.
Multiple jobs are executed by the CPU by switching between them,
but the switches occur so frequently. Thus, the user can receives an
immediate response.
Operating system uses CPU scheduling and multiprogramming to
provide each user with a small portion of a time.
Advantage of Timesharing operating systems is it reduces CPU idle
time. Dr.B.Hemantha Kumar. RVR&JC CE 21
Types of Operating System
• Multiprocessor Systems(Parallel Systems): A
Multiprocessor system consists of several processors that
share a common physical memory. Multiprocessor
system provides higher computing power and speed.
• In multiprocessor system all processors operate under
single operating system. Multiplicity of the processors
and how they do act together are transparent to the
others.
• Multiprocessor systems have three main advantages:
– Increased throughput.
– Economy of scale.
– Increased reliability
Dr.B.Hemantha Kumar. RVR&JC CE 22
Types of Operating System
• Multiprocessor Systems: Advantages:
• Increased throughput. By increasing the number of processors, we
expect to get more work done in less time.
• Economy of scale. Multiprocessor systems can cost less than
equivalent multiple single-processor systems, because they can
share peripherals, mass storage, and power supplies.
• Increased reliability. If functions can be distributed properly
among several processors, then the failure of one processor will
not halt the system, only slow it down. If we have ten processors
and one fails, then each of the remaining nine processors can pick
up a share of the work of the failed processor. Thus, the entire
system runs only 10 percent slower, rather than failing altogether.

Dr.B.Hemantha Kumar. RVR&JC CE 23


Types of Operating System
Distributed operating System: Distributed systems use
multiple central processors to serve multiple real time
application and multiple users. Data processing jobs are
distributed among the processors accordingly to which one
can perform each job most efficiently.
The processors communicate with one another through
various communication lines (such as high-speed buses or
telephone lines). These are referred as loosely coupled
systems or distributed systems. Processors in a distributed
system may vary in size and function. These processors are
referred as sites, nodes, computers and so on.

Dr.B.Hemantha Kumar. RVR&JC CE 24


Types of Operating System
Distributed operating System:
The advantages of distributed systems are following:
• With resource sharing facility user at one site may be able to use
the resources available at another.
• Speedup the exchange of data with one another via electronic
mail.
• If one site fails in a distributed system, the remaining sites can
potentially continue operating.
• Better service to the customers.
• Reduction of the load on the host computer.
• Reduction of delays in data processing

Dr.B.Hemantha Kumar. RVR&JC CE 25


Types of Operating System
• Real Time operating System:Real-time systems are used when
there are rigid time requirements on the operation of a processor
or the flow of data and real-time systems can be used as a control
device in a dedicated application. A real-time operating system
must have well-defined, fixed time constraints, otherwise the
system will fail. For example, Scientific experiments, medical
imaging systems, industrial control systems, weapon systems,
robots, air traffic control systems, etc.
There are two types of real-time operating systems.
• Hard real-time systems: Hard real-time systems guarantee that
critical tasks complete on time. Soft real-time systems
• Soft real-time systems are less restrictive. A critical real-time task
gets priority over other tasks and retains the priority until it
completes.
Dr.B.Hemantha Kumar. RVR&JC CE 26
Operating System
• Operating-System Operations: As mentioned earlier, modern
operating systems are interrupt driven. Events are almost always
signaled by the occurrence of an interrupt or a trap.
• A trap (or an exception) is a software-generated interrupt caused
either by an error (for example, division by zero or invalid memory
access) or by a specific request from a user program that an
operating-system service be performed.

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


components . These are User mode and kernel mode
• Mode bit provided by hardware

Dr.B.Hemantha Kumar. RVR&JC CE 27


Operating System

Transition from user to kernel mode.


Dr.B.Hemantha Kumar. RVR&JC CE 28
Operating System
• A bit, called the mode bit, is added to the hardware of
the computer to indicate the current mode: kernel (0) or
user (1).
• With the mode bit, we can distinguish between a task
that is executed on behalf of the operating system and
one that is executed on behalf of the user.
• Provides ability to distinguish when system is running
user code or kernel code
• Some instructions designated as privileged, only
executable in kernel mode .

Dr.B.Hemantha Kumar. RVR&JC CE 29


Operating System
• We must ensure that the operating system maintains
control over the CPU.
• To accomplish this goal, we can use a 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).
• A variable timer is generally implemented by a fixed-rate
clock and a counter.

Dr.B.Hemantha Kumar. RVR&JC CE 30


OPERATING SYSTEM FUNCTIONS
Process Management:
• A process is a program in execution. It is a unit of work within the system.
Program is a passive entity, process is an active entity.
• Process needs resources to accomplish its task like CPU, memory, I/O,
files , Initialization data
• Process termination requires reclaim of any reusable resources
• Single-threaded process has one program counter specifying location of
next instruction to execute
• Process executes instructions sequentially, one at a time, until
completion
• Multi-threaded process has one program counter per thread
• Typically system has many processes, some user, some operating system
running concurrently on one or more CPUs
• Concurrency by multiplexing the CPUs among the processes / threads
Dr.B.Hemantha Kumar. RVR&JC CE 31
OPERATING SYSTEM FUNCTIONS
Process Management Activities: The operating system is
responsible for the following activities in connection with
process management:
• Creating and deleting both user and system processes
• Suspending and resuming processes
• Providing mechanisms for process synchronization
• Providing mechanisms for process communication
• Providing mechanisms for deadlock handling

Dr.B.Hemantha Kumar. RVR&JC CE 32


OPERATING SYSTEM FUNCTIONS
Memory Management:
• All data in memory before and after processing
• All instructions in memory in order to execute
• Memory management determines what is in memory when
• Optimizing CPU utilization and computer response to users

Memory management activities


• Keeping track of which parts of memory are currently being used
and by whom
• Deciding which processes (or parts thereof) and data to move into
and out of memory
• Allocating and deallocating memory space as needed
Dr.B.Hemantha Kumar. RVR&JC CE 33
OPERATING SYSTEM FUNCTIONS
Storage Management : To make the computer system convenient for
users, the operating system provides a uniform, logical view of
information storage.
• The operating system abstracts from the physical properties of its
storage devices to define a logical storage unit, known as file.
• The operating system maps files onto physical media and accesses
these files via the storage devices.
File-System management : Files usually organized into directories
• A file is a collection of related information defined by its creator.
Commonly, files represent programs (both source and object
forms) and data.

Dr.B.Hemantha Kumar. RVR&JC CE 34


OPERATING SYSTEM FUNCTIONS
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

Dr.B.Hemantha Kumar. RVR&JC CE 35


OPERATING SYSTEM FUNCTIONS
Mass-Storage Management
• Usually disks used to store data that does not fit in main
memory or data that must be kept for a “long” period of
time .
• Hence, proper management of disk storage is of central
importance to a computer system.
• The operating system is responsible for the following
activities in connection with disk management:
• Free-space management
• Storage allocation
• Disk scheduling

Dr.B.Hemantha Kumar. RVR&JC CE 36


OPERATING SYSTEM FUNCTIONS
• 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—
on a temporary basis. When we need a particular piece of
information, we first 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.
• In addition, internal programmable registers, such as index
registers, provide a high-speed cache for main memory.

Dr.B.Hemantha Kumar. RVR&JC CE 37


OPERATING SYSTEM FUNCTIONS
• Caching:

Migration of integer A from disk to register


cache coherency: In a multiprocessor environment where, each of
the CPUs 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 in parallel, we must make sure that an update 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 issue (handled below the operating-system level).

Dr.B.Hemantha Kumar. RVR&JC CE 38


OPERATING SYSTEM
Protection and Security:
• Protection is any mechanism for controlling the access of
processes or users to the resources defined by a computer system.
• Security – defend a system from external and internal attacks. Such
attacks spread across a huge range and include viruses and worms,
denial-of service attacks.
• Prevention of some of these attacks is considered an operating-
system function on some systems, while other systems leave it to
policy or additional software.
• Protection and security require the system to be able to distinguish
among all its users. Most operating systems maintain a list of user
names and associated user identifiers (user IDs). These numerical
IDs are unique, one per user.
Dr.B.Hemantha Kumar. RVR&JC CE 39
OPERATING SYSTEM
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.
• Operating system services are provided for the convenience of the
programmer, to make the programming task easier.

Dr.B.Hemantha Kumar. RVR&JC CE 40


OPERATING SYSTEM
Operating-System Services

Dr.B.Hemantha Kumar. RVR&JC CE 41


OPERATING SYSTEM
Operating-System Services
One set of operating system services provides functions that are
helpful to the user:
• User interface, Program execution, I/O operations, File-system
manipulation, Communications, Error detection

• Another set of operating system functions exists not for helping


the user but rather for ensuring the efficient operation of the
system itself:
Resource allocation, Accounting, Protection and security,

Dr.B.Hemantha Kumar. RVR&JC CE 42


OPERATING SYSTEM
One set of operating system services provides functions that are helpful to
the user:
User interface:
• Almost all operating systems have a user interface (UI). This interface can
take several forms. One is a command-line interface (CLI), which uses
text commands and a method for entering them (say, a keyboard for
typing in commands in a specific format with specific options).
• Another is a batch interface, in which commands and directives to
control those commands are entered into files, and those files are
executed.
• Most commonly, a graphical user interface (GUI) is used. Here, the
interface is a window system with a pointing device to direct I/O, choose
from menus, and make selections and a keyboard to enter text.
• Some systems provide two or all three of these variations.

Dr.B.Hemantha Kumar. RVR&JC CE 43


OPERATING SYSTEM
One set of operating system services provides functions that are helpful to
the user:
• Program execution: The system must be able to load a program
into memory and to run that program. The program must be able
to end its execution, either normally or abnormally (indicating
error).
• I/O operations. A running program may require I/O, which may
involve a file or an I/O device. For specific devices, special
functions may be desired (such as recording to a CD or DVD drive
or blanking a display screen).
• For efficiency and protection, users usually cannot control I/O
devices directly.
• Therefore, the operating system must provide a means to do I/O.

Dr.B.Hemantha Kumar. RVR&JC CE 44


OPERATING SYSTEM
One set of operating system services provides functions that are helpful to
the user:
• File-system manipulation. Programs need to read and write files
and directories.
• They also need to create and delete them by name, search for a
given file, and list file information.
• Some operating systems include permissions management to allow
or deny access to files or directories based on file ownership.

Dr.B.Hemantha Kumar. RVR&JC CE 45


OPERATING SYSTEM
One set of operating system services provides functions that are helpful to
the user:
• Communications. There are many circumstances in which one
process needs to exchange information with another process.
• Communication may occur between processes that are executing
on the same computer or between processes that are executing on
different computer systems in a network.
• Communications may be implemented via shared memory, in
which two or more processes read and write to a shared section of
memory, or message passing, in which packets of information in
predefined formats are moved between processes by the
operating system.

Dr.B.Hemantha Kumar. RVR&JC CE 46


OPERATING SYSTEM
• Error detection.Errors may occur in the CPU and memory
hardware (such as a memory error or a power failure),
• in I/O devices (such as a 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).
• For each type of error, the operating system should take the
appropriate action to ensure correct and consistent computing.
Sometimes, it has no choice but to halt the system. At other times,
it might terminate an error-causing process or return an error code
to a process for the process to detect and possibly correct.

Dr.B.Hemantha Kumar. RVR&JC CE 47


OPERATING SYSTEM
Another set of operating system functions exists not for helping the
user but rather for ensuring the efficient operation of the system
itself:
• Resource allocation,
• Accounting,
• Protection and security,
Resource allocation. When there are multiple users or multiple jobs
running at the same time, resources must be allocated to each of
them. The operating system manages many different types of
resources such as CPU , main memory, file storage, I/O devices.
Operating systems have CPU-scheduling routines that take into
account the speed of the CPU printers, USB storage drives, and other
peripheral devices.

Dr.B.Hemantha Kumar. RVR&JC CE 48


OPERATING SYSTEM
• Accounting. We want to keep track of which users use how much
and what kinds of computer resources. This record keeping may be
used for accounting (so that users can be billed) or simply for
accumulating usage statistics.
• Protection and security. The owners of information stored in a
multiuser or networked computer system may want to control use
of that information. Protection involves ensuring that all access to
system resources is controlled. Security of the system from
outsiders is also important. Such security starts with requiring each
user to authenticate himself or herself to the system, usually by
means of a password, to gain access to system resources.

Dr.B.Hemantha Kumar. RVR&JC CE 49

You might also like