Operatring System Ppt
Operatring System Ppt
Process management
• A program in its execution state is known as process.
• A process needs certain resources including CPU time, memory, files and
I/O devices to accomplish its task.
• These resources are either given to the process when it is created or
allocated to it while it is running.
• A program is a passive entity such as contents of a file stored on the disk
whereas a process is an active entity
The operating system is responsible for the following activities in
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.
2. Memory management
Main memory is a collection of quickly accessible data shared by the CPU
and I/O devices.
The central processor reads instructions from main memory (during
instruction-fetch cycle) and both reads and writes data from main
memory (during data-fetch cycle).
The operating system is responsible for the following activities in memory
management:
• Keeping track of which parts of memory are currently being used and by
whom
• Deciding which processes and data to move into and out of memory
• Allocating and deallocating memory space as needed.
3. File-System Management
The operating system is responsible for the following activities with file
management:
• Creating and deleting files
• Creating and deleting directories to organize files
• Supporting primitives for manipulating files and directories
• Backing up files on stable (nonvolatile) storage media.
8.Command Interpreter
• To interface with the operating System we use command-line interface or command interpreter
that allows users to directly enter commands that are to be performed by the operating system.
• The main function of the command interpreter is to get and execute the user-specified
commands. Many of the commands given at this level manipulate files: create, delete, list, print,
copy, execute, and so on. Eg: MS-DOS and UNIX shells.
Types of Operating System
• Single user Operating system This OS provides the environment for
single user i.e. only one user can interact with the system at a time.
Eg: MS-DOS, MS WINDOWS-XP, ME, 2000 etc.
• In a typical sequence first the editor is been called to create a source code of user
program then translator is been called to convert source code into its object code, finally
the loader is been called to load its executable program into main memory for
execution.
• If syntax errors are detected than the whole program must be restarted from the
beginning.
Batch processing Operating System
Job 2 • Advantages:
• Efficient memory utilization
Job 3 • Throughput increases. (Throughput is a measure of how
many units of information a system can process in a given amount of time.)
• A real time system has well defined fixed time constraints, processing
must be done within defined constraints or system will get failed.
• System that controls scientific system, experimenting medical system,
industrial control system and certain display systems are real time
system.
• They are also applicable to automobile engine fuel system, home
appliance controller and weapon systems.
• There are two types of real system:
• i) Hard real time system This system guarantees that critical tasks be
completed on time. For this all the delays in the system should be
bounded, from the retrieval of stored data to the time it takes
operating system to finish any request made to it.
• ii) Soft real time system This is less restrictive type of system defined
as not hard real-time, simply providing that a critical real-time task
will receive priority over other tasks and that it will retain the priority
until it completes.
Operating-System Services
1) User interface Almost all operating systems have a user interface
(UI).This interface can take several forms.
• command-line interface (CLI) which uses text commands.
• batch interface, in which commands and directives to control those
commands are entered into files
• graphical user interface (GUI) the interface is a window system with a
pointing device to direct I/O, choose from menus, and make
selections and keyboard to enter text.
2) Program execution:- The system should to load a program into memory and to run
that program. The program must be able to end its execution.
4)File-system manipulation:- Programs need to read and write files. They also need to
create and delete. Finally, some programs include permissions management to allow or
deny access to files or directories based on file ownership.
5) Communications. There are many circumstances in which one process needs
to exchange information with another process.
Such communication may occur between processes that are executing on the
same computer or between processes that are executing on different
computer systems tied together by a computer network.
6)Error detection. Errors may occur in the CPU and memory hardware (such as a
memory error or a power failure), in I/O devices (a network failure, 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, or too-great use of CPU time).
For each type of error, the operating system should take the appropriate
action to ensure correct and consistent computing.
7. Resource allocation. When there are multiple users or multiple jobs running at
the same time, resources must be allocated to each of them. Many different
types of resources are managed by the operating system trough various methods
such as CPU-scheduling.
8. Accounting. OS keeps track of which users use how much and what kind of
computer resources. This record keeping may be used for accounting
1. User Space
2. Kernel
User Space
• No hardware access
• Convenient environment user apps
Kernel
• Heart of OS
• Interacts with hardware
• Very first part of OS to load on start-up.
Functions of Kernel/OS
• Process management
• Memory management
• File management
• I/O management
Process management
ØAs the resource is locked while a process executes its critical section hence no other
process can access it. The acquire() function acquires the lock and the release()
function releases the lock.
Synchronization Hardware
ØThe critical section problem could be solved easily in a single-processor environment
if we could disallow interrupts to occur while a shared variable or resource is being
modified.
ØWe could be sure that the current sequence of instructions would be allowed to
execute in order without pre-emption. Unfortunately, this solution is not feasible in a
multiprocessor environment.
ØThis message transmission lag, delays entry of threads into critical section and the
system efficiency decreases.
acquire() {
while(!available)
; /* busy wait */
available=false;;
}
release() {
available=true;
}
ØIf there is an open table, or the semaphore is greater than zero, then he can
take that resource and sit at the table.
Ødecrement the value of its argument S as soon as it would become non-
negative.
Signal()
ØIt also called V (for Dutch “Verhogen” meaning to increment)
ØNear the room are five philosophers who spend most of their time
thinking,
process P[i]
while true do
{
THINK;
WAIT(CHOPSTICK[i]);
WAIT(CHOPSTICK[(i+1 )mod 5]); //pickup
EAT;
SIGNAL(CHOPSTICK[i]);
SIGNAL(CHOPSTICK[(i+1) mod 5]); //putdown
}
ØA philosopher may THINK indefinitely.
ØIf all the philosophers pick their left chopstick simultaneously. Then none of them can
eat and deadlock occurs.
ØAn even philosopher should pick the right chopstick and then the left chopstick while an
odd philosopher should pick the left chopstick and then the right chopstick.
ØA philosopher should only be allowed to pick their chopstick if both are available at the
same time.
qA set of blocked processes each holding a resource and waiting to acquire a
resource held by another process in the set.
q A process requests resources; and if the resources are not available at that
time, the process enters a waiting state.
q Sometimes, a waiting process is never again able to change state, because the
resources it has requested are held by other waiting processes.
• Pi requests instance of Rj Pi
Pi
• Pi is holding an instance of Rj
Rj
Example of a Resource Allocation Graph
Will there be a deadlock here?
Resource Allocation Graph With A Cycle But
No Deadlock
Basic Facts
■ If graph contains no cycles means no deadlock.
■ Ignore the problem and pretend that deadlocks never occur in the
system; used by most operating systems, including UNIX.
The Methods (continued
■ Deadlock Detection -Let the deadlock occur in the system and then
attempt to recover the system from deadlock.
Deadlock prevention
For a deadlock to occur, each of the four necessary conditions must hold. By ensuring
that at least one of these conditions cannot hold, we can prevent the occurrence of the
deadlock.
■Mutual Exclusion – not required for sharable resources; must hold for non-sharable
resources.
■Hold and Wait – must guarantee that whenever a process requests a resource, it
does not hold any other resources.
● Require process to request and be allocated all its resources before it begins
execution, or allow process to request resources only when the process has
none.
● Low resource utilization; starvation possible
Deadlock Prevention (Cont.)
■ No Preemption –
● If a process that is holding some resources requests another resource that
cannot be immediately allocated to it, then all resources currently being held
are released.
● Preempted resources are added to the list of resources for which the process
is waiting.
● Process will be restarted only when it can regain its old resources, as well as
the new ones that it is requesting.
■ Circular Wait – impose a total ordering of all resource types, and require that
each process requests resources in an increasing order of enumeration.
Deadlock Avoidance
Requires that the system has some additional a priori information available.
■ Simplest and most useful model requires that each process declare the maximum
number of resources of each type that it may need.
■ Detection algorithm
■ Recovery scheme
Safe State
§A state is safe if the system can allocate resources to each process (up to its
maximum) in some order and still avoid a deadlock. More formally, a system is
in a safe state only if there exists a safe sequence.
§A sequence of processes <P1, P2, ... , Pn> is a safe sequence for the current
allocation state if, for each Pi, the resource requests that Pi can still make can
be satisfied by the currently available resources plus the resources held by all
Pj, with j < i.
Safe, Unsafe , Deadlock State
•If a system is in safe state, there is no deadlock.
•Avoidance: making sure the system will not enter an unsafe state.
Resource-Allocation Graph Algorithm
■ Claim edge Pi - -> Rj indicated that process Pi may request resource Rj;
represented by a dashed line.
converting the request edge to an assignment edge does not result in the
formation of a cycle in the resource allocation graph
§The resource allocation graph is not much useful if there are multiple
instances for a resource
Example formal algorithms
■ Banker’s Algorithm
■ Resource-Request Algorithm
■ Safety Algorithm
Banker’s Algorithm
■ Multiple instances.
■ When a process gets all its resources it must return them in a finite
amount of time.
Data Structures
Let n = number of processes, and m = number of resources types
•Max: n x m matrix.
If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj
•Allocation: n x m matrix.
If Allocation [i,j] = k then Pi is currently allocated k instances of Rj
•Need: n x m matrix.
If Need [i,j] = k, then Pi may need k more instances of Rj to complete its task
4.If Finish [i] == true for all i, then the system is in a safe state,
otherwise it is unsafe
The Algorithm requires m x n2 operations to detect whether the system is in deadlocked state
Resource-Request Algorithm for Process Pi
Request = request vector for process Pi.
If Requesti [j] = k then process Pi wants k instances of
resource type Rj.
P1 200 322
P2 302 902
P3 211 222
P4 002 433
Example (Cont.)
■ The content of the matrix. Need is defined to be Max – Allocation.
Need
ABC
P0 743
P1 122
P2 600
P3 011
P4 431
The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies safety
criteria
Example P1 Request (1,0,2) (Cont.)
P1 302 020
P2 301 600
P3 211 011
P4 002 431
■ Executing safety algorithm shows that sequence
<P1, P3, P4, P0, P2> satisfies safety requirement.
■ Detection algorithm
■ Recovery scheme
Single Instance of Each Resource Type
Algorithm requires an order of O(m x n2) operations to detect whether the system is in
deadlocked state.
Example of Detection Algorithm
Sequence <P0, P2, P3, P1, P4> will result in Finish[i] = true for all i
Example (Cont.)
■ State of system?
● Can reclaim resources held by process P0, but insufficient resources to fulfill other
processes; requests.
● Deadlock exists, consisting of processes P1, P2, P3, and P4.
Recovery from Deadlock: Process Termination
■ Abort all deadlocked processes.
■ Rollback – return to some safe state, restart process for that state.