0% found this document useful (0 votes)
18 views71 pages

Unit 1 Os - PPT

Uploaded by

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

Unit 1 Os - PPT

Uploaded by

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

UNIT I - INTRODUCTION AND

PROCESSES MANAGEMENT

Operating System Overview- Operating System


Objectives and Functions, Evolution of Operating
systems, Computer System Organization.
Processes- Process Concept, Process Scheduling,
Operations on Processes- Interprocess
Communication, Communication in Client-Server
System
Operating System (OS)
• 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.
• It is a software which manages hardware.
• An operating System controls the allocation of
resources and services such as memory, processors,
devices and information.
Operating System Overview
Operating System:
• A program that controls the execution of application
programs
• An interface between applications and hardware
• Exploits the hardware resources of one or more
processors
• Provides a set of services to system users
• Manages secondary memory and I/O devices
Operating System Objectives and
functions
• Convenience
– Makes the computer more convenient to use
• Efficiency
– Allows computer system resources to be used in
an efficient manner
• Ability to evolve
– Permit effective development, testing, and
introduction of new system functions without
interfering with service
Functions of an operating system

• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users
Memory Management
• Memory management refers to management of
Primary Memory or Main Memory
• Main memory access directly by the CPU.
• Operating System does the following activities for
memory management.
• Keeps tracks of primary memory i.e. what part of it
are in use by whom, what part are not in use.
• In multiprogramming, OS decides which process will
get memory when and how much.
• Allocates the memory when the process requests it to
do so.
• De-allocates the memory when the process no longer
needs it or has been terminated.
Processor Management
• In multiprogramming environment, OS decides which
process gets the processor when and how much time.
This function is called process scheduling.
• Operating System does the following activities for
processor management.
• Keeps tracks of processor and status of process.
Program responsible for this task is known as traffic
controller.
• Allocates the processor(CPU) to a process.
• De-allocates processor when processor is no longer
required.
Device Management

• OS manages device communication via their respective


drivers.
• Operating System does the following activities for device
management.
• Keeps tracks of all devices. Program responsible for this
task is known as the I/O controller.
• Decides which process gets the device when and for how
much time.
• Allocates the device in the efficient way.
• De-allocates devices.
File Management
• A file system is normally organized into directories for
easy navigation and usage.
• These directories may contain files and other directions.
• Operating System does the following activities for file
management.
• Keeps track of information, location, uses, status etc.
The collective facilities are often known as file system.
• Decides who gets the resources.
• Allocates the resources.
• De-allocates the resources.
Other Important Activities
• Security -- By means of password and similar other
techniques, preventing unauthorized access to programs and
data.
• Control over system performance -- Recording delays
between request for a service and response from the system.
• Job accounting -- Keeping track of time and resources used
by various jobs and users.
• Error detecting aids -- Production of dumps, traces, error
messages and other debugging and error detecting aids.
• Coordination between other softwares and users --
Coordination and assignment of compilers, interpreters,
assemblers and other software to the various users of the
computer systems.
Services Provided by the Operating System

• Program development
– Editors and debuggers
• Program execution
• Access to I/O devices
• Controlled access to files
• System access
Services Provided by the Operating System
• Error detection and response
– Internal and external hardware errors
• Memory error
• Device failure
– Software errors
• Arithmetic overflow
• Access forbidden memory locations
– Operating system cannot grant request of application
• Accounting
– Collect usage statistics
– Monitor performance
– Used to anticipate future enhancements
– Used for billing purposes
Evolution of Operating Systems
• 1971: Intel announces the microprocessor
• 1972: IBM comes out with VM: the Virtual
Machine Operating System
• 1973: UNIX 4th Edition is published
• 1973: Ethernet
• 1974 The Personal Computer Age begins
• 1974: Gates and Allen wrote BASIC for the Altair
• 1976: Apple II
• August 12, 1981: IBM introduces the IBM PC
Evolution of Operating Systems
• 1983 Microsoft begins work on MS-Windows
• 1984 Apple Macintosh comes out
• 1990 Microsoft Windows 3.0 comes out
• 1991 GNU/Linux
• 1992 The first Windows virus comes out
• 1993 Windows NT
• 2007: iOS
• 2008: Android OS
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
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
Storage Structure
• Main memory – only large storage media that the
CPU can access directly.
• Secondary storage – extension of main memory
that provides large nonvolatile storage capacity.
• Magnetic disks – rigid metal or glass platters
covered with magnetic recording material
– Disk surface is logically divided into tracks, which are
subdivided into sectors.
– The disk controller determines the logical interaction
between the device and the computer.
Storage Hierarchy
• Storage systems organized in hierarchy.
– Speed
– Cost
– Volatility
• Caching – copying information into faster
storage system; main memory can be viewed
as a last cache for secondary storage.
Storage-Device Hierarchy
Cache Memory
Cache Memory

• Contains a copy of a portion of main memory


• Processor first checks cache
• If not found in cache, the block of memory
containing the needed information is moved to the
cache and delivered to the processor
Migration of Integer A from Disk
to Register
• Multitasking environments must be careful to use most recent
value, no matter where it is stored in the storage hierarchy

Multiprocessor environment must provide cache coherency


in hardware such that all CPUs have the most recent value in
their cache
• Distributed environment situation even more complex
– Several copies of a datum can exist
Direct Memory Access

• Transfers a block of data


directly to or from memory
• An interrupt is sent when
the transfer is complete
• Processor continues with
other work
Direct Memory Access (DMA)

• I/O exchanges occur directly with memory


• Processor grants I/O module authority to read from
or write to memory
• Relieves the processor responsibility for the
exchange
Direct memory access
• Traditional I/O Primary
memory
– Polling approach:
• CPU transfer data between the
controller data registers and the
primary memory
• Output operations - device driver CPU
copies data from the application
process data area to the controller;
Controller
vice versa for input operations
– Interrupt driven I/O approach - the
interrupt handler is responsible for the Device
transfer task
Direct memory access
• DMA controllers are able to read and write Primary
information directly from /to primary memory
memory, with no software intervention
• The I/O operation has to be initiated by the
driver
• DMA hardware enables the data transfer to be
accomplished without using the CPU at all
• The DMA controller must include an address CPU
register (and address generation hardware)
loaded by the driver with a pointer to the
relevant memory block; this pointer is used
by the DMA hardware to locate the target Controller
block in primary memory
Device
Typical DMA

• Mimics the
processor
• Transfers data
to/from memory
over system bus
Process Concept
• An operating system executes a variety of programs:
• Batch system – jobs
• 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
• Multiple parts
• The program code, also called text section
• Current activity including program counter, processor
registers
• Stack containing temporary data
• Function parameters, return addresses, local
variables
• Data section containing global variables
• Heap containing memory dynamically allocated during
run time
Process Concept
• Program is passive entity stored on disk
(executable file), process is active
– Program becomes process when executable file
loaded into memory
• Execution of program started via GUI mouse clicks,
command line entry of its name, etc
• One program can be several processes
– Consider multiple users executing the same
program
Process in Memory
Process State

• As a process executes, it changes state


– new: The process is being created
– running: Instructions are being executed
– waiting: The process is waiting for some event
to occur
– ready: The process is waiting to be assigned to a
processor
– terminated: The process has finished execution
Diagram of Process State
Process Control Block (PCB)
Information associated with each process
(also called task control block)
• Process state – running, waiting, etc
• Program counter – location of instruction
to next execute
• CPU registers – contents of all process-
centric registers
• CPU scheduling information- priorities,
scheduling queue pointers
• Memory-management information –
memory allocated to the process
• Accounting information – CPU used,
clock time elapsed since start, time limits
• I/O status information – I/O devices
allocated to process, list of open files
Process Scheduling
• Maximize CPU use, quickly switch processes onto CPU
for time sharing
• Process scheduler selects among available processes for
next execution on CPU
• Maintains scheduling queues of processes
– 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
– Processes migrate among the various queues
Representation of Process Scheduling
 Queueing diagram represents queues, resources,
flows
Schedulers
• Short-term scheduler (or CPU scheduler) – selects which process
should be executed next and allocates CPU
– Sometimes the only scheduler in a system
– Short-term scheduler is invoked frequently (milliseconds)  (must be
fast)
• Long-term scheduler (or job scheduler) – selects which processes
should be brought into the ready queue
– Long-term scheduler is invoked infrequently (seconds, minutes) 
(may be slow)
– The long-term scheduler controls the degree of multiprogramming
• Processes can be described as either:
– I/O-bound process – spends more time doing I/O than computations,
many short CPU bursts
– CPU-bound process – spends more time doing computations; few
very long CPU bursts
• Long-term scheduler strives for good process mix
Addition of Medium Term
Scheduling
Medium-term scheduler can be added if degree of multiple
programming needs to decrease
Remove process from memory, store on disk, bring back in
from disk to continue execution: swapping
Operations on Processes

• System must provide mechanisms


for:
– process creation,
– process termination,
Process Creation
• Parent process create children processes, which, in turn
create other processes, forming a tree of processes
• Generally, process identified and managed via a process
identifier (pid)
• Resource sharing options
– Parent and children share all resources
– Children share subset of parent’s resources
– Parent and child share no resources
• Execution options
– Parent and children execute concurrently
– Parent waits until children terminate
A Tree of Processes in Linux
Process Creation
• Address space
– Child duplicate of parent
– Child has a program loaded into it
• UNIX examples
– fork() system call creates new process
– exec() system call used after a fork() to
replace the process’ memory space with a
new program
C Program Forking Separate
Process
Process Termination
• Process executes last statement and then asks the
operating system to delete it using the exit() system call.
– Returns status data from child to parent (via wait())
– Process’ resources are deallocated by operating system
• Parent may terminate the execution of children processes
using the abort() system call. Some reasons for doing so:
– Child has exceeded allocated resources
– Task assigned to child is no longer required
– The parent is exiting and the operating systems does
not allow a child to continue if its parent terminates
Interprocess Communication
• Processes within a system may be independent or cooperating
• Cooperating process can affect or be affected by other processes,
including sharing data
• Reasons for cooperating processes:
– Information sharing
– Computation speedup
– Modularity
– Convenience
• Cooperating processes need interprocess communication
(IPC)
• Two models of IPC
– Shared memory
– Message passing
Communications Models
(a) Message passing. (b) shared memory.
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
– Computation speed-up
– Modularity
– Convenience
Producer-Consumer Problem
• Paradigm for cooperating processes,
producer process produces
information that is consumed by a
consumer process
– unbounded-buffer places no practical
limit on the size of the buffer
– bounded-buffer assumes that there is a
fixed buffer size
Bounded-Buffer – Shared-Memory
Solution
• Shared data
#define BUFFER_SIZE 10
typedef struct {
...
} item;

item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;

• Solution is correct, but can only use BUFFER_SIZE-1 elements


Bounded-Buffer – Producer
item next_produced;
while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
Bounded Buffer – Consumer
item next_consumed;
while (true) {
while (in == out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;

/* consume the item in next consumed */


}
Interprocess Communication – Shared
Memory
• An area of memory shared among the
processes that wish to communicate
• The communication is under the control of the
users processes not the operating system.
• Major issues is to provide mechanism that will
allow the user processes to synchronize their
actions when they access shared memory.
• Synchronization is discussed in great details
in Chapter 5.
Interprocess Communication –
Message Passing
• 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)
– receive(message)

• The message size is either fixed or variable


Message Passing
• If processes P and Q wish to communicate, they need to:
– Establish a communication link between them
– Exchange messages via send/receive
• Implementation issues:
– How are links established?
– Can a link be associated with more than two processes?
– How many links can there be between every pair of
communicating processes?
– What is the capacity of a link?
– Is the size of a message that the link can accommodate fixed
or variable?
– Is a link unidirectional or bi-directional?
Message Passing (Cont.)
• Implementation of communication link
– Physical:
• Shared memory
• Hardware bus
• Network
– Logical:
• Direct or indirect
• Synchronous or asynchronous
• Automatic or explicit buffering
Direct Communication
 Processes must name each other explicitly:
 send (P, message) – send a message to process P
 receive(Q, message) – receive a message from process
Q
 Properties of communication link
 Links are established automatically
 A link is associated with exactly one pair of
communicating processes
 Between each pair there exists exactly one link
 The link may be unidirectional, but is usually bi-
directional
Indirect Communication
• Messages are directed and received from mailboxes
(also referred to as ports)
– Each mailbox has a unique id
– Processes can communicate only if they share a
mailbox
• Properties of communication link
– Link established only if processes share a common
mailbox
– A link may be associated with many processes
– Each pair of processes may share several
communication links
– Link may be unidirectional or bi-directional
Indirect Communication
• Operations
– create a new mailbox (port)
– send and receive messages through mailbox
– 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
– Blocking send -- the sender is blocked until the message is
received
– Blocking receive -- the receiver is blocked until a message
is available
• Non-blocking is considered asynchronous
– Non-blocking send -- the sender sends the message and
continue
– Non-blocking receive -- the receiver receives:
 A valid message, or
 Null message
 Different combinations possible
 If both send and receive are blocking, we have a rendezvous
Synchronization (Cont.)
 Producer-consumer becomes trivial

message next_produced;
while (true) {
/* produce an item in next produced */
send(next_produced);
}
message next_consumed;
while (true) {
receive(next_consumed);

/* consume the item in next consumed */


}
Buffering

• Queue of messages attached to the link.


• implemented in one of three ways
1.Zero capacity – no messages are queued on
a link.
Sender must wait for receiver (rendezvous)
2.Bounded capacity – finite length of n
messages
Sender must wait if link full
3.Unbounded capacity – infinite length
Sender never waits
Communications in Client-Server
Systems
• Sockets
• Remote Procedure Calls
• Pipes
• Remote Method Invocation (Java)
Sockets

• A socket is defined as an endpoint for


communication
• Concatenation of IP address and port – a number
included at start of message packet to differentiate
network services on a host
• The socket 161.25.19.8:1625 refers to port 1625 on
host 161.25.19.8
• Communication consists between a pair of sockets
• All ports below 1024 are well known, used for
standard services
• Special IP address 127.0.0.1 (loopback) to refer to
system on which process is running
Socket Communication
Sockets in Java

• Three types of sockets


– Connection-
oriented (TCP)
– Connectionless
(UDP)
– MulticastSocket
class– data can be
sent to multiple
recipients
• Consider this “Date”
server:
Remote Procedure Calls

• Remote procedure call (RPC) abstracts procedure


calls between processes on networked systems
– Again uses ports for service differentiation
• 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 performs
the procedure on the server
• On Windows, stub code compile from specification
written in Microsoft Interface Definition
Language (MIDL)
Remote Procedure Calls (Cont.)
• Data representation handled via External Data
Representation (XDL) format to account for
different architectures
– Big-endian and little-endian
• Remote communication has more failure scenarios
than local
– Messages can be delivered exactly once rather
than at most once
• OS typically provides a rendezvous (or
matchmaker) service to connect client and server
Pipes
• Acts as a conduit allowing two processes to
communicate
• Issues:
– Is communication unidirectional or bidirectional?
– In the case of two-way communication, is it half or
full-duplex?
– Must there exist a relationship (i.e., parent-child)
between the communicating processes?
– Can the pipes be used over a network?
• Ordinary pipes – cannot be accessed from outside the
process that created it. Typically, a parent process creates
a pipe and uses it to communicate with a child process
that it created.
• Named pipes – can be accessed without a parent-child
relationship.
Ordinary Pipes

• Ordinary Pipes allow communication in standard


producer-consumer style
• Producer writes to one end (the write-end of the pipe)
• Consumer reads from the other end (the read-end of the
pipe)
• Ordinary pipes are therefore unidirectional
• Require parent-child relationship between
communicating processes
• Windows calls these anonymous pipes
• See Unix and Windows code samples in textbook
Named Pipes

• Named Pipes are more powerful than


ordinary pipes
• Communication is bidirectional
• No parent-child relationship is necessary
between the communicating processes
• Several processes can use the named pipe for
communication
• Provided on both UNIX and Windows
systems

You might also like