0% found this document useful (0 votes)
31 views24 pages

UNIT-1 Os-1

Uploaded by

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

UNIT-1 Os-1

Uploaded by

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

UNIT-1

Operating System

An Operating system is a collection of software that manages computer hardware resources and Provides
common services for computer programs. The operating system is a vital component of the system
software in a computer system.

An operating System is an intermediary between users and computer hardware. It provides users an
environment in which a user can execute programs conveniently and efficiently.

 An operating System controls the allocation of resources and services such as memory,
processors, devices and information.
 Operating system is a control program which controls the execution of user programs and
operations of I/O devices.

Operating system goals:

Execute user programs and make solving user problems easier.

Make the computer system convenient to use.

Computer System Components

1) Hardware – provides basic computing resources (CPU, memory, I/O devices)

2) Operating system – controls and coordinates the use of the hardware among the various application
programs for the various users.

Krishna chaitanya institute of science & technology Page 1


3) Applications programs – define the ways in which the system resources are used to solve the
computing problems of the users (compilers, database systems, video games, business programs)

4) Users (people, machines, other computers)

Abstract View of System Components

Operating System Structures


An Operating system provides the environment within which programs are executed. The design of a new
operating system is a major task. The goals must be well defined before the design begins. The type of the
system desired is the basis for choices among various algorithms and strategies.

The three aspects of the operating systems to be explored are:

1) Examining the services that it provides.

2) The interface that the operating system makes available to users and programmers.

3) Disassembling the system into its components and their interconnections.

System Components

A process is a program in execution. A process needs certain resources, including CPU time, memory,
files, and I/O devices, to accomplish its task.

The operating system is responsible for the following activities in connection with process management.

Krishna chaitanya institute of science & technology Page 2


 Process creation and deletion
 Process suspension and resumption
 Providing mechanisms for process synchronization
 Providing mechanisms for process communication
 Providing mechanisms for deadlock handling

Main-Memory Management

Memory is a large array of words or bytes, each with its own address. It is a repository of quickly
accessible data shared by the CPU and I/O devices.

Main memory is a volatile storage device. It loses its contents in the case of system failure.

The operating system is responsible for the following activities in connections with memory management

 Keeping track of which parts of memory are currently being used and by whom

 Deciding which processes to be loaded into memory when memory space becomes available.
 Allocating and de-allocating memory space as needed.

File Management

A file is a collection of related information defined by its creator. Commonly, files represent programs
and data. The operating system is responsible for the following activities in connections with file
management:

 Creating and deleting files.


 Creating and deleting directories
 Support of primitives for manipulating files and directories.
 Mapping files onto secondary storage.
 File backup on stable (nonvolatile) storage media.

I/O System Management

The I/O system consists of:

 A buffer-caching system
 A general device-driver interface
 Drivers for specific hardware devices

Secondary-Storage Management

Since main memory (primary storage) is volatile and too small to accommodate all data and programs
permanently, the computer system must provide secondary storage to back up main memory.

Most modern computer systems use disks as the principle on-line storage medium, for both programs and
data

Krishna chaitanya institute of science & technology Page 3


The operating system is responsible for the following activities in connection with disk management:

 Free space management


 Storage allocation
 Disk scheduling

Networking (Distributed Systems)

A distributed system is a collection processor that do not share memory or a clock. Each processor has its
own local memory. The processors in the system are connected through a communication network.

Communication takes place using a protocol. A distributed system provides user access to various
systems resources. Access to a shared resource allows:

 Computation speed-up

 Increased data availability

 Enhanced reliability

Protection System

Protection refers to a mechanism for controlling access by programs, processes, or users to both system
and user resources. The protection mechanism must:

 Distinguish between authorized and unauthorized usage

 Specify the controls to be imposed

 Provide a means of enforcement

Command-Interpreter System

Many commands are given to the operating system by control statements which deal with:

 Process creation and management

 I/O handling

 Secondary-storage management

 Main-memory management

 File-system access

 Protection

 Networking

Operating System Services

An Operating System provides services to both the users and to the programs. It provides programs, an
environment to execute. It provides users, services to execute the programs in a convenient manner.

Krishna chaitanya institute of science & technology Page 4


Following are few common services provided by operating systems.

 Program execution
 I/O operations
 File System manipulation
 Communication
 Error Detection
 Resource Allocation
 Protection
Program execution
Operating system handles many kinds of activities from user programs to system programs like printer
spooler, name servers, file server etc. Each of these activities is encapsulated as a process.
A process includes the complete execution context (code to execute, data to manipulate, registers, OS
resources in use). Following are the major activities of an operating system with respect to program
management.
 Loads a program into memory.
 Executes the program.
 Handles program's execution.
 Provides a mechanism for process synchronization.
 Provides a mechanism for process communication.
 Provides a mechanism for deadlock handling.
I/O Operation
I/O subsystem comprised of I/O devices and their corresponding driver software. Drivers hides the
peculiarities of specific hardware devices from the user as the device driver knows the peculiarities of the
specific device.
Operating System manages the communication between user and device drivers. Following are the major
activities of an operating system with respect to I/O Operation.
 I/O operation means read or write operation with any file or any specific I/O device.
 Program may require any I/O device while running.
 Operating system provides the access to the required I/O device when required.

File system manipulation


A file represents a collection of related information. Computer can store files on the disk (secondary
storage), for long term storage purpose. Few examples of storage media are magnetic tape, magnetic disk
and optical disk drives like CD, DVD. Each of these media has its own properties like speed, capacity,
and data transfer rate and data access methods.
A file system is normally organized into directories for easy navigation and usage. These directories may
contain files and other directions. Following are the major activities of an operating system with respect
to file management.
 Program needs to read a file or write a file.
 The operating system gives the permission to the program for operation on file.
 Permission varies from read-only, read-write, denied and so on.
 Operating System provides an interface to the user to create/delete files.
 Operating System provides an interface to the user to create/delete directories.
 Operating System provides an interface to create the backup of file system.
Communication

Krishna chaitanya institute of science & technology Page 5


In case of distributed systems which are a collection of processors that do not share memory, peripheral
devices, or a clock, operating system manages communications between processes. Multiple processes
with one another through communication lines in the network.
OS handles routing and connection strategies, and the problems of contention and security. Following are
the major activities of an operating system with respect to communication.
 Two processes often require data to be transferred between them.
 The both processes can be on the one computer or on different computer but are connected
through computer network.
 Communication may be implemented by two methods either by Shared Memory or by Message
passing.
Error handling
Error can occur anytime and anywhere. Error may occur in CPU, in I/O devices or in the memory
hardware. Following are the major activities of an operating system with respect to error handling.
 OS constantly remains aware of possible errors.
 OS takes the appropriate action to ensure correct and consistent computing.
Resource Management
In case of multi-user or multi-tasking environment, resources such as main memory, CPU cycles and files
storage are to be allocated to each user or job. Following are the major activities of an operating system
with respect to resource management.
 OS manages all kind of resources using schedulers.
 CPU scheduling algorithms are used for better utilization of CPU.
Protection
Considering computer systems having multiple users the concurrent execution of multiple processes, then
the various processes must be protected from each another's activities.
Protection refers to mechanism or a way to control the access of programs, processes, or users to the
resources defined by computer systems. Following are the major activities of an operating system with
respect to protection.
 OS ensures that all access to system resources is controlled.
 OS ensures that external I/O devices are protected from invalid access attempts.
 OS provides authentication feature for each user by means of a password.
Accounting

Keep track of and record which users use how much and what kinds of computer resources for
accounting or for accumulating usage statistics.

System Calls

System calls provide the interface between a running program and the operating system. Certain systems
allow system calls to be made directly form a high-level programming language such as C, C++ program
in which these calls normally resemble predefined function or sub-routine calls.

Types of System Calls

 Process control
o end, abort
o load, execute
o create process, terminate process

Krishna chaitanya institute of science & technology Page 6


o get process attributes, set process attributes
o wait for time
o wait event, signal event
o allocate and free memory
 File management
o create file, delete file
o open, close
o read, write, reposition
o get file attributes, set file attributes
 Device management
o request device, release device
o read, write, reposition
o get device attributes, set device attributes
o logically attach or detach devices
 Information maintenance
o get time or date, set time or date
o get system data, set system data
o get process, file, or device attributes
o set process, file, or device attributes
 Communications
o create, delete communication connection
o send, receive messages
o transfer status information
o attach or detach remote devices

Communication Models

Communication may take place using either message passing or shared memory

Message Passing Shared Memory

System Programs

Krishna chaitanya institute of science & technology Page 7


System programs provide a convenient environment for program development and execution. The can be
divided into:

o File management
o Status information
o File modification
o Programming language support
o Program loading and execution
o Communications
o Application programs

File management: These programs create, delete, copy, rename, print, dump, list and generally manipulate
files and directories.

Status information: Some programs simply ask the system for the date, time, amount of available
memory or disk space, number of users, or similar status information. That information is then formatted,
and is printed to the terminal or other output device or file.

File modification: Several text editors may be available to create and modify the content of files stored on
disk or tape.

Programming-language support: Compilers, assemblers, and interpreters for common programming


languages (such as C, C++, Java, Visual Basic, and PERL) are often provided to the user with the
operating system. Some of these programs are now priced and provided separately.

Program loading and execution: Once a program is assembled or compiled, it must be loaded in to
memory. To be executed the system may provide absolute loaders, re-locatable loaders, linkage editors,
and overlay loaders. Debugging systems for either higher-level languages or machine language are
needed also.

Communications: These programs provide the mechanism for creating virtual connections among
processes, users and different computer systems. They allow users to send messages to one another’s

screens, to browse web pages, to send electronic-mail messages, to log in remotely, or to transfer files
from one machine to another.

Most users’ view of the operation system is defined by system programs, not the actual system calls.

System Structure

A system as large and complex as a modern operating system 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 of these modules should be a well-defined
partition of the system, with carefully defined inputs, outputs and function.

1) Simple Structure

MS-DOS System Structure

Krishna chaitanya institute of science & technology Page 8


MS-DOS – written to provide the most functionality in the least space

 Not divided into modules


 Although MS-DOS has some structure, its interfaces and levels of functionality are not well
separated.

MS-DOS Layer Structure

UNIX System Structure

UNIX – 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; a large number of functions for one level

UNIX System Structure

Krishna chaitanya institute of science & technology Page 9


2) 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.

With modularity, layers are selected such that each uses functions (operations) and services of only
lower-level layer

An Operating System Layer

OS/2 Layer Structure

Krishna chaitanya institute of science & technology Page 10


3) Microkernel System Structure

Moves as much from the kernel into “user” space. Communication takes place between user modules
using message passing.

Benefits:

o Easier to extend a microkernel

o Easier to port the operating system to new architectures

o More reliable (less code is running in kernel mode)

o More secure

Drawbacks:

o Performance overhead of user space to kernel space communication

Example: QNX, Windows NT operating systems.

QNX is a real-time operating system that is also based upon the microkernel design. The QNX
microkernel provides services for message passing and process scheduling. It also handles low-level
network communication and hardware interrupts. All other services in QNX are provided by standard.
Processes that run outside the kernel in user mode.

Windows NT Client-Server Structure

Krishna chaitanya institute of science & technology Page 11


Virtual Machines

A virtual machine takes the layered approach to its logical conclusion. It treats hardware and the
operating system kernel as though they were all hardware.

A virtual machine provides an interface identical to the underlying bare hardware

The operating system creates the illusion of multiple processes, each executing on its own processor with
its own (virtual) memory

The resources of the physical computer are shared to create the virtual machines

o CPU scheduling can create the appearance that users have their own processor

o Spooling and a file system can provide virtual card readers and virtual line printers

o A normal user time-sharing terminal serves as the virtual machine operator’s console

System Models

Krishna chaitanya institute of science & technology Page 12


Non-virtual Machine Virtual Machine

Advantages of Virtual Machines

 The virtual-machine concept provides complete protection of system resources since each virtual
machine is isolated from all other virtual machines. This isolation, however, permits no direct
sharing of resources.
 A virtual-machine system is a perfect vehicle for operating-systems research and development.
System development is done on the virtual machine, instead of on a physical machine and so does
not disrupt normal system operation.

Disadvantages of Virtual Machines

 The virtual machine concept is difficult to implement due to the effort required to provide an
exact duplicate to the underlying machine

Java Virtual Machine

Compiled Java programs are platform-neutral byte codes executed by a Java Virtual Machine (JVM)

JVM consists of

Class loader

o Class verifier
o Runtime interpreter

Just-In-Time (JIT) compilers increase performance

The Java Virtual Machine

System Design and Implementation


Krishna chaitanya institute of science & technology Page 13
System Design 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

Mechanisms and Policies

Mechanisms determine how to do something; policies decide what will be done

The separation of policy from mechanism is a very important principle, it allows maximum flexibility if
policy decisions are to be changed later

System Implementation

Traditionally written in assembly language, operating systems can now be written in higher-level
languages

Code written in a high-level language:

o Can be written faster

o Is more compact.

o Is easier to understand and debug

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

Process Concept
 An operating system executes a variety of programs:
o Batch system – jobs

o Time-shared systems – user programs or tasks

 Textbook uses the terms job and process almost interchangeably


 Process – a program in execution; process execution must progress in sequential fashion
 A process includes:
o program counter

o stack

Krishna chaitanya institute of science & technology Page 14


o data section

Process State
 As a process executes, it changes state
o new: The process is being created

o running: Instructions are being executed

o waiting: The process is waiting for some event to occur

o ready: The process is waiting to be assigned to a process

 terminated: The process has finished

Process Control Block (PCB)


 Information associated with each process
 Process state
 Program counter
 CPU registers
 CPU scheduling information
 Memory-management information
 Accounting information
 I/O status information

Krishna chaitanya institute of science & technology Page 15


CPU Switch From Process to Process

Process Scheduling Queues


 Job queue – set of all processes in the system
 Ready queue – set of all processes residing in main memory, ready and waiting to execute
 Device queues – set of processes waiting for an I/O device
 Process migration between the various queues
Ready Queue And Various I/O Device Queues

Krishna chaitanya institute of science & technology Page 16


Representation of Process Scheduling

Schedulers
 Long-term scheduler (or job scheduler) – selects which processes should be brought into
the ready queue
 Short-term scheduler (or CPU scheduler) – selects which process should be executed next
and allocates CPU
Addition of Medium Term Scheduling

Krishna chaitanya institute of science & technology Page 17


 Short-term scheduler is invoked very frequently (milliseconds) Þ (must be fast)
 Long-term scheduler is invoked very infrequently (seconds, minutes) Þ (may be slow)
 The long-term scheduler controls the degree of multiprogramming
 Processes can be described as either:
o I/O-bound process – spends more time doing I/O than computations, many short
CPU bursts
o CPU-bound process – spends more time doing computations; few very long CPU
bursts
Context Switch
 When CPU switches to another process, the system must save the state of the old process
and load the saved state for the new process
 Context-switch time is overhead; the system does no useful work while switching
 Time dependent on hardware support
Process Creation
 Parent process create children processes, which, in turn create other processes, forming a
tree of processes
 Resource sharing
o Parent and children share all resources

o Children share subset of parent’s resources

o Parent and child share no resources

 Execution
o Parent and children execute concurrently

Krishna chaitanya institute of science & technology Page 18


o Parent waits until children terminate

 Address space
o Child duplicate of parent

o Child has a program loaded into it

 UNIX examples
o fork system call creates new process

o exec system call used after a fork to replace the process’ memory space with a
new program
Processes Tree on a UNIX System

Process Termination
Process executes last statement and asks the operating system to decide it (exit)
Process executes last statement and asks the operating system to decide it (exit)

Cooperating Processes
 Independent process cannot affect or be affected by the execution of another
process
 Cooperating process can affect or be affected by the execution of another process
 Advantages of process cooperation
 Information sharing

Krishna chaitanya institute of science & technology Page 19


 Computation speed-up
 Modularity
 Convenience
Producer-Consumer Problem
 Paradigm for cooperating processes, producer process produces information, that is
consumed by a consumer process
o unbounded-buffer places no practical limit on the size of the buffer

o bounded-buffer assumes that there is a fixed buffer size

Interprocess Communication (IPC)


 Mechanism for processes to communicate and to synchronize their actions
 Message system – processes communicate with each other without
resorting to shared variables
 IPC facility provides two operations:
Send (message) – message size fixed or variable
Receive (message)
 If P and Q wish to communicate, they need to:
o establish a communication link between them

o exchange messages via send/receive

 Implementation of communication link


o physical (e.g., shared memory, hardware bus)

o logical (e.g., logical properties)

Direct Communication
 Processes must name each other explicitly:
o send (P, message) – send a message to process P

o receive(Q, message) – receive a message from process Q

 Properties of communication link


o Links are established automatically

o A link is associated with exactly one pair of communicating processes

Krishna chaitanya institute of science & technology Page 20


o Between each pair there exists exactly one link

o The link may be unidirectional, but is usually bi-directional

Indirect Communication
 Messages are directed and received from mailboxes (also referred to as ports)
o Each mailbox has a unique id

o Processes can communicate only if they share a mailbox

 Properties of communication link


o Link established only if processes share a common mailbox

o A link may be associated with many processes

o Each pair of processes may share several communication links

o Link may be unidirectional or bi-directional

 Operations
o create a new mailbox

o send and receive messages through mailbox

o destroy a mailbox

 Primitives are defined as:


Send (A, message) – send a message to mailbox A
Receive (A, message) – receive a message from mailbox A
Synchronization
 Message passing may be either blocking or non-blocking
 Blocking is considered synchronous
o Blocking send has the sender block until the message is received

o Blocking receive has the receiver block until a message is


available
 Non-blocking is considered asynchronous
 Non-blocking send has the sender send the message and continue
 Non-blocking receive has the receiver receive a valid message or null

Krishna chaitanya institute of science & technology Page 21


Client-Server Communication
 Sockets
 Remote Procedure Calls
 Remote Method Invocation (Java)
Sockets
 A socket is defined as an endpoint for communication
 Concatenation of IP address and port
 The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
 Communication consists between a pair of sockets
Socket Communication

Remote Procedure Calls


 Remote procedure call (RPC) abstracts procedure calls between processes on networked
systems.
 Stubs – client-side proxy for the actual procedure on the server.
 The client-side stub locates the server and marshalls the parameters.
 The server-side stub receives this message, unpacks the marshalled parameters, and
peforms the procedure on the server.

Krishna chaitanya institute of science & technology Page 22


Execution of RPC

Remote Method Invocation


 Remote Method Invocation (RMI) is a Java mechanism similar to RPCs.
 RMI allows a Java program on one machine to invoke a method on a remote object.

Krishna chaitanya institute of science & technology Page 23


Marshalling Parameters

Krishna chaitanya institute of science & technology Page 24

You might also like