Вы находитесь на странице: 1из 34

What is an Operating System?

A program between computer users and computer hardware

To manage and use computer hardware in an efficient manner

Operating system goals:

To provide an environment for users to execute programs in a


convenient and efficient manner

To ensure the correct operation of the computer system

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

An operating system (OS) is software that manages computer hardware and software resources and provides
common services for computer programs. The operating system is an essential component of the system software in a
computer system. Application programs usually require an operating system to function.
Time-sharing operating systems schedule tasks for efficient use of the system and may also include accounting
software for cost allocation of processor time, mass storage, printing, and other resources.
For hardware functions such as input and output and memory allocation, the operating system acts as an intermediary
between programs and the computer hardware,[1][2] although the application code is usually executed directly by the
hardware and frequently makes a system call to an OS function or be interrupted by it. Operating systems can be found
on many devices that contain a computerfrom cellular phones and video game consoles to supercomputers and web
servers.
Examples of popular modern operating systems include Android, BSD, iOS, Linux, OS X, QNX, Microsoft Windows,
[3]

Windows Phone, and IBM z/OS. All these examples, except Windows, Windows Phone and z/OS, share roots

in UNIX.

Operating System Components


Kernel

Program execution

Interrupts

Modes

Memory management

Virtual memory

Multitasking

Disk access and file systems

Device drivers

Networking

Security

User interface
Graphical user interfaces

For detail :refer http://en.wikipedia.org/wiki/Operating_system

Processes
A program is a passive thing -- just a file on the disk with code that is potentially runnable.
A process is one instance of a program in execution; at any instance, there may be many processes
running copies of a single program (e.g., an editor): each is a separate, independent process.

Process A

Processor: Provides a set of instructions along with the capability of


automatically executing a series of those instructions.

Thread: A minimal software processor in whose context a series of


instructions can be executed. Saving a thread context implies stopping the
current execution and saving all the data needed to continue the
execution at a later stage.

Process: A software processor in whose context one or more threads may


be executed. Executing a thread, means executing a series of instructions
in the context of that thread.

Introduction to threads
Thread is a light weighted process.
The analogy: thread is to process as process is to machine.
Each thread runs strictly sequentially and has its own program
counter and stack to keep track of where it is.
Threads share the CPU just as processes do: first one thread runs,
then another does.
Threads can create child threads and can block waiting for system
calls to complete.
All threads have exactly the same address space. They share code section,
data section, and OS resources (open files & signals).
They share the same global variables. One thread can read, write, or even
completely wipe out another threads stack.
Threads can be in any one of several states: running, blocked, ready, or
terminated.
There is no protection between threads:
(1) it is immpossible

(2) it should not be necessary: a process is always owned by a single user,


who has created multiple threads so that they can cooperate, not fight.

a) Three processes with one thread each.


three threads

b) One process with

Process Scheduling
In a multiprogramming system, all the processes that run on a particular
system seek for the CPU time.
Hence there is a need of CPU scheduling algorithm that reduces the
followings as far as possible.
Average waiting time
Average response time and
Average turn around time

CPU/Process Scheduling
The assignment of physical processors to processes allows processors to
accomplish work. The problem of determining when processors should be assigned
and to which processes is called processor scheduling or CPU scheduling.

When more than one process is runable, the operating system must decide which
one first. The part of the operating system concerned with this decision is called
the scheduler, and algorithm it uses is called the scheduling algorithm.

The process scheduler is the component of the operating system that is responsible for deciding whether the currently running process should
continue running and, if not, which process should run next. There are four events that may occur where the scheduler needs to step in and make
this decision:

1.

The current process goes from the running to the waiting state because it issues an I/O request or some operating system request
that cannot be satisfied immediately.

2.

3.

The current process terminates.

A timer interrupt causes the scheduler to run and decide that a process has run for its allotted interval of time and it is time to move it
from the running to the ready state.

4.

An I/O operation is complete for a process that requested it and the process now moves from the waiting to the ready state. The
scheduler may then decide to preempt the currently-running process and move this newly-ready process into the running state.

Goals of Scheduling (objectives)

In this section we try to answer following question: What the scheduler try to
achieve?
Many objectives must be considered in the design of a scheduling discipline. In
particular, a scheduler should consider fairness, efficiency, response time,
turnaround time, throughput, etc., Some of these goals depends on the system one
is using for example batch system, interactive system or real-time system, etc. but
there are also some goals that are desirable in all systems.
General Goals

Fairness
Fairness is important under all circumstances. A scheduler makes sure that
each process gets its fair share of the CPU and no process can suffer indefinite
postponement. Note that giving equivalent or equal time is not fair. Think of safety
control and payroll at a nuclear plant.
Policy Enforcement
The scheduler has to make sure that system's policy is enforced. For example,
if the local policy is safety then the safety control processes must be able to run
whenever they want to, even if it means delay in payroll processes.
Efficiency
Scheduler should keep the system (or in particular CPU) busy cent percent of
the time when possible. If the CPU and all the Input/Output devices can be kept
running all the time, more work gets done per second than if some components are
idle.

Response Time
A scheduler should minimize the response time for interactive user.
Turnaround
A scheduler should minimize the time batch users must wait for an output.
Throughput
A scheduler should maximize the number of jobs processed per unit time.
A little thought will show that some of these goals are contradictory. It can be
shown that any scheduling algorithm that favors some class of jobs hurts another
class of jobs. The amount of CPU time available is finite, after all.
Preemptive Vs Nonpreemptive Scheduling

The Scheduling algorithms can be divided into two categories with respect to how
they deal with clock interrupts.
Nonpreemptive Scheduling
A scheduling discipline is nonpreemptive if, once a process has been given the
CPU, the CPU cannot be taken away from that process.
Following are some characteristics of nonpreemptive scheduling
1. In nonpreemptive system, short jobs are made to wait by
longer jobs but the overall treatment of all processes is fair.
2. In nonpreemptive system, response times are more
predictable because incoming high priority jobs can not
displace waiting jobs.
3. In nonpreemptive scheduling, a schedular executes jobs in
the following two situations.
a. When a process switches from running state to the
waiting state.
b. When a process terminates.
Preemptive Scheduling
A scheduling discipline is preemptive if, once a process has been given the CPU
can taken away.

The strategy of allowing processes that are logically runable to be temporarily


suspended is called Preemptive Scheduling and it is contrast to the "run to
completion" method.

Inter process Communication


Process of communication between two processes that reside in same or different
systems.
E.g. communication of client and server

Here a process of client communicates with another process of server for a


specific purpose.

IPC - 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 (Communication)

Information sharing

Computation speed-up

Modularity

Convenience

Dangers of process cooperation (Communication)

Data corruption, deadlocks, increased complexity

Requires processes to synchronize their processing

Purposes for IPC


Data Transfer
Sharing Data
Event notification

Resource Sharing and Synchronization


Process Control

Mechanisms used for communication and synchronization


the different ways of communication between the processes.
Message Passing
Shared Memory
RPC
Remote Procedure Call (RPC)
RPC is an interaction between a client and a server
Client invokes procedure on sever
Server executes the procedure and pass the result back to client
Calling process is suspended (blocked) and proceeds only after getting the result from
server
RPC Motivation
Transport layer message passing consists of two types of primitives: send and receive

May be implemented in the OS or through add-on libraries

Messages are composed in user space and sent via a send() primitive.
When processes are expecting a message they execute a receive() primitive.

Receives are often blocking

Messages lack access transparency.

Differences in data representation, need to understand message-passing


process, etc.

Programming is simplified if processes can exchange information using techniques


that are similar to those used in a shared memory environment.
The Remote Procedure Call (RPC) Model
A high-level network communication interface
Based on the single-process procedure call model.
Client request: formulated as a procedure call to a function on the server.
Servers reply: formulated as function return
Conventional Procedure Calls
1. Initiated when a process calls a function or procedure
2. The caller is suspended until the called function completes.
3. Arguments & return address are pushed onto the process stack.
4. Variables local to the called function are pushed on the stack
5. Control passes to the called function
6. The called function executes, returns value(s) either through parameters or in
registers.
7. The stack is popped.
8. Calling function resumes executing

Figure: Principle of RPC between a client


and server program.

RPC and Client-Server


RPC forms the basis of most client-server systems.
Clients formulate requests to servers as procedure calls
Servers reply: formulated as function return
Problem with Conventional RPC
Access Transparency in not maintained
Modern RPC

Modern RPC
1. The client procedure calls the client stub in the normal way.
2. The client stub builds a message including parameters, name or number of procedure
to be called etc and calls the local operating system. The packaging of arguments into
a network message is called marshaling.
3. The client's as sends the message to the remote OS via a system call to the local
kernel. To transfer the message some protocol (either connectionless or connectionoriented) are used.
4. The remote OS gives the message to the server stub.
5. The server stub unpacks the parameters and calls the server.
6. The server does the work and returns the result to the stub.
7. The server stub packs it in a message and calls its local OS.
8. The server's OS sends the message to the client's OS.
9. The client's OS gives the message to the client stub.
10. The stub unpacks the result and returns to the waiting client procedure.

RPC Issues: Binding


A local kernel calls remote kernel in RPC along with some parameters through a
particular port.
The local kernel must know the remotes port through which it is communicating
with.
The process of finding out or assigning the port and corresponding system (client or
server) is called binding.
Binding
Determines remote procedure and machine on which it will be executed
Checks compatibility of the parameters passed
Dynamic Binding
Use Binding Server

Virtual machine
In computing, a virtual machine (VM) is an emulation of a particular computer system. Virtual machines
operate based on thecomputer architecture and functions of a real or hypothetical computer, and their
implementations may involve specialized hardware, software, or a combination of both.
Classification of virtual machines can be based on the degree to which they implement functionality of
targeted real machines. That way, system virtual machines (also known as full virtualization VMs) provide a
complete substitute for the targeted real machine and a level of functionality required for the execution of a
complete operating system. On the other hand, process virtual machines are designed to execute a
single computer program by providing an abstracted and platform-independent program execution
environment.
Different virtualization techniques are used, based on the desired usage. Native execution is based on
direct virtualization of the underlying raw hardware, thus it provides multiple "instances" of the
same architecture a real machine is based on, capable of running complete operating systems. Some
virtual machines can also emulate different architectures and allow execution of software applications and
operating systems written for another CPU or architecture. Operating systemlevel virtualization allows
resources of a computer to be partitioned via kernel's support for multiple isolated user space instances,
which are usually calledcontainers and may look and feel like real machines from the end users' point of
view.
Some computer architectures are capable of hardware-assisted virtualization, which enables efficient full
virtualization by using virtualization-specific hardware capabilities, primarily from the host CPUs.

Definitions[edit]
A virtual machine (VM) is a software implementation of a machine (for example, a computer) that executes programs
like a physical machine. Virtual machines are separated into two major classes, based on their use and degree of
correspondence to any real machine:

A system virtual machine provides a complete system platform which supports the execution of a
complete operating system (OS).[1] These usually emulate an existing architecture, and are built with the purpose of
either providing a platform to run programs where the real hardware is not available for use (for example,
executing on otherwise obsolete platforms), or of having multiple instances of virtual machines leading to more
efficient use of computing resources, both in terms of energy consumption and cost effectiveness (known
as hardware virtualization, the key to a cloud computing environment), or both.

A process virtual machine (also, language virtual machine) is designed to run a single program, which means
that it supports a single process. Such virtual machines are usually closely suited to one or more programming
languages and built with the purpose of providing program portability and flexibility (amongst other things). An
essential characteristic of a virtual machine is that the software running inside is limited to the resources and
abstractions provided by the virtual machineit cannot break out of its virtual environment.

A VM was originally defined by Popek and Goldberg as "an efficient, isolated duplicate of a real machine". Current use
includes virtual machines which have no direct correspondence to any real hardware. [2]

System virtual machines[edit]


See also: Hardware virtualization and Comparison of platform virtual machines
System virtual machine advantages:

Multiple OS environments can co-exist on the same primary hard drive, with a virtual partition that allows
sharing of files generated in either the "host" operating system or "guest" virtual environment. Adjunct software
installations, wireless connectivity, and remote replication, such as printing and faxing, can be generated in any of
the guest or host operating systems. Regardless of the system, all files are stored on the hard drive of the host OS.

Application provisioning, maintenance, high availability and disaster recovery are inherent in the virtual
machine software selected.

Can provide emulated hardware environments different from the host's instruction set architecture (ISA),
through emulation or by using just-in-time compilation.

The main disadvantages of VMs are:

A virtual machine is less efficient than an actual machine when it accesses the host hard drive indirectly.

When multiple VMs are concurrently running on the hard drive of the actual host, adjunct virtual machines may
exhibit a varying and/or unstable performance (speed of execution and malware protection). This depends on the
data load imposed on the system by other VMs, unless the selected VM software provides temporal isolation
among virtual machines.

Malware protection for VM's are not necessarily compatible with the "host", and may require separate
software.

Multiple VMs running their own guest operating system are frequently engaged for server consolidation in order to avoid
interference from separate VMs on the same actual machine platform.
The desire to run multiple operating systems was the initial motivation for virtual machines, so as to allow time-sharing
among several single-tasking operating systems. In some respects, a system virtual machine can be considered a
generalization of the concept of virtual memory that historically preceded it. IBM's CP/CMS, the first systems to allow full
virtualization, implemented time sharing by providing each user with a single-user operating system, the CMS. Unlike
virtual memory, a system virtual machine entitled the user to write privileged instructions in their code. This approach
had certain advantages, such as adding input/output devices not allowed by the standard system. [3]
As technology evolves virtual memory for purposes of virtualization, new systems of memory overcommitment may be
applied to manage memory sharing among multiple virtual machines on one actual computer operating system. It may
be possible to share "memory pages" that have identical contents among multiple VM's that run on the same actual
machine. This may result in mapping them to the same physical page, by a technique known as Kernel SamePage
Merging. This is particularly useful for read-only pages, such as those that contain code segments. In particular would
be the case of multiple virtual machines running the same or similar software, software libraries, web servers,
middleware components, etc. The guest operating systems do not need to be compliant with the host hardware, thereby
making it possible to run different operating systems on the same computer (e.g., Microsoft Windows, Linux, or previous
versions of an operating system to support future software.
The use of virtual machines to support separate guest operating systems is popular in regard to embedded systems. A
typical use would be to support an actual-time operating system simultaneously with a preferred complex operating
system, such as Linux or Windows. Another use would be for novel and unproven software still in the developmental
stage, such as sandbox. Virtual machines have other advantages for operating system development, and may include
improved debugging access and faster reboots.[4]

Process virtual machines[edit]


See also: Application virtualization, Run-time system and Comparison of application virtual machines
A process VM, sometimes called an application virtual machine, or Managed Runtime Environment (MRE), runs as a
normal application inside a host OS and supports a single process. It is created when that process is started and
destroyed when it exits. Its purpose is to provide a platform-independent programming environment that abstracts away
details of the underlying hardware or operating system, and allows a program to execute in the same way on any
platform.
A process VM provides a high-level abstraction that of a high-level programming language (compared to the low-level
ISA abstraction of the system VM). Process VMs are implemented using an interpreter; performance comparable to
compiled programming languages is achieved by the use of just-in-time compilation.
This type of VM has become popular with the Java programming language, which is implemented using the Java virtual
machine. Other examples include the Parrot virtual machine, and the .NET Framework, which runs on a VM called
the Common Language Runtime. All of them can serve as an abstraction layer for any computer language.
A special case of process VMs are systems that abstract over the communication mechanisms of a (potentially
heterogeneous) computer cluster. Such a VM does not consist of a single process, but one process per physical
machine in the cluster. They are designed to ease the task of programming concurrent applications by letting the
programmer focus on algorithms rather than the communication mechanisms provided by the interconnect and the OS.
They do not hide the fact that communication takes place, and as such do not attempt to present the cluster as a single
machine.[citation needed]

Unlike other process VMs, these systems do not provide a specific programming language, but are embedded in an
existing language; typically such a system provides bindings for several languages (e.g., C and FORTRAN).[citation
needed]

Examples are PVM (Parallel Virtual Machine) and MPI (Message Passing Interface). They are not strictly virtual

machines, as the applications running on top still have access to all OS services, and are therefore not confined to the
system model.

Memory management
In operating systems, memory management is the function responsible for managing the computer's primary memory.
[1]:pp-105208

The memory management function keeps track of the status of each memory location, either allocated or free. It
determines how memory is allocated among competing processes, deciding who gets memory, when they receive it,
and how much they are allowed. When memory is allocated it determines which memory locations will be assigned. It
tracks when memory is freed or unallocated and updates the status.
Contents
[hide]

1 Memory

management techniques

1.1 Single

1.2 Partitioned

1.3 Paged

1.4 Segmented

2 See

3 References

contiguous allocation
allocation

memory management
memory management

also

Memory management techniques[edit]

Single contiguous allocation[edit]


Single allocation is the simplest memory management technique. All the computer's memory, usually with the exception
of a small portion reserved for the operating system, is available to the single application. MS-DOS is an example of a
system which allocates memory in this way. An embedded system running a single application might also use this
technique.
A system using single contiguous allocation may still multitask by swapping the contents of memory to switch among
users. Early versions of the Music operating system used this technique.

Partitioned allocation[edit]
Partitioned allocation divides primary memory into multiple memory partitions, usually contiguous areas of memory.
Each partition might contain all the information for a specificjob or task. Memory management consists of allocating a
partition to a job when it starts and unallocating it when the job ends.
Partitioned allocation usually requires some hardware support to prevent the jobs from interfering with one another or
with the operating system. The IBM System/360 used alock-and-key technique. Other systems used base and
bounds registers which contained the limits of the partition and flagged invalid accesses. The UNIVAC 1108 Storage
Limits Register had separate base/bound sets for instructions and data. The system took advantage of memory
interleaving to place what were called the i bank and d bank in separate memory modules.[2]:3-3
Partitions may be either static, that is defined at Initial Program Load (IPL) or boot time or by the computer operator,
or dynamic, that is automatically created for a specific job.IBM System/360 Operating System Multiprogramming with a
Fixed Number of Tasks (MFT) is an example of static partitioning, and Multiprogramming with a Variable Number of
Tasks (MVT) is an example of dynamic. MVT and successors use the term region to distinguish dynamic partitions from
static ones in other systems.[3]:73
Partitions may be relocatable using hardware typed memory, like the Burroughs Corporation B5500, or base and
bounds registers like the PDP-10 or GE-635. Relocatable partitions are able to be compacted to provide larger chunks
of contiguous physical memory. Compaction moves "in-use" areas of memory to eliminate "holes" or unused areas of
memory caused by process termination in order to create larger contiguous free areas. [4]:94
Some systems allow partitions to be swapped out to secondary storage to free additional memory. Early versions of
IBM's Time Sharing Option (TSO) swapped users in and out of a single time-sharing partition.[5]

Paged memory management[edit]


Main article: Virtual memory
Paged allocation divides the computer's primary memory into fixed-size units called page frames, and the program's
virtual address space into pages of the same size. The hardware memory management unit maps pages to frames. The
physical memory can be allocated on a page basis while the address space appears contiguous.
Usually, with paged memory management, each job runs in its own address space. However, there are some single
address space operating systems that run all processes within a single address space, such as IBM i, which runs all
processes within a large address space, and IBM OS/VS2 SVS, which ran all jobs in a single 16MiB virtual address
space.
Paged memory can be demand-paged when the system can move pages as required between primary and secondary
memory.

Segmented memory management[edit]


Main article: Memory segmentation
Segmented memory is the only memory management technique that does not provide the user's program with a 'linear
and contiguous address space."[1]:p.165 Segments are areas of memory that usually correspond to a logical grouping of
information such as a code procedure or a data array. Segments require hardware support in the form of asegment
table which usually contains the physical address of the segment in memory, its size, and other data such as access
protection bits and status (swapped in, swapped out, etc.)

Segmentation allows better access protection than other schemes because memory references are relative to a specific
segment and the hardware will not permit the application to reference memory not defined for that segment.
It is possible to implement segmentation with or without paging. Without paging support the segment is the physical unit
swapped in and out of memory if required. With paging support the pages are usually the unit of swapping and
segmentation only adds an additional level of security.
Addresses in a segmented system usually consist of the segment id and an offset relative to the segment base address,
defined to be offset zero.
The Intel IA-32 (x86) architecture allows a process to have up to 16,383 segments of up to 4GiB each. IA-32 segments
are subdivisions of the computer's linear address space, the virtual address space provided by the paging hardware.[6]
The Multics operating system is probably the best known system implementing segmented memory. Multics segments
are subdivisions of the computer's physical memory of up to 256 pages, each page being 1K 36-bit words in size,
resulting in a maximum segment size of 1MiB (with 9-bit bytes, as used in Multics). A process could have up to 4046
segments.

Memory management (Next)


Memory management is the functionality of an operating system which handles or manages primary memory. Memory management keeps track
of each and every memory location either it is allocated to some process or it is free. It checks how much memory is to be allocated to processes.
It decides which process will get memory at what time. It tracks whenever some memory gets freed or unallocated and correspondingly it updates
the status.
Memory management provides protection by using two registers, a base register and a limit register. The base register holds the smallest legal
physical memory address and the limit register specifies the size of the range. For example, if the base register holds 300000 and the limit register
is 1209000, then the program can legally access all addresses from 300000 through 411999.

Instructions and data to memory addresses can be done in following ways


Compile time -- When it is known at compile time where the process will reside, compile time binding is used to generate the absolute

code.

Load time -- When it is not known at compile time where the process will reside in memory, then the compiler generates re-locatable

code.

Execution time -- If the process can be moved during its execution from one memory segment to another, then binding must be
delayed to be done at run time

Dynamic Loading
In dynamic loading, a routine of a program is not loaded until it is called by the program. All routines are kept on disk in a re-locatable load format.
The main program is loaded into memory and is executed. Other routines methods or modules are loaded on request. Dynamic loading makes
better memory space utilization and unused routines are never loaded.

Dynamic Linking
Linking is the process of collecting and combining various modules of code and data into a executable file that can be loaded into memory and
executed. Operating system can link system level libraries to a program. When it combines the libraries at load time, the linking is called static
linking and when this linking is done at the time of execution, it is called as dynamic linking.
In static linking, libraries linked at compile time, so program code size becomes bigger whereas in dynamic linking libraries linked at execution
time so program code size remains smaller.

Logical versus Physical Address Space


An address generated by the CPU is a logical address whereas address actually available on memory unit is a physical address. Logical address
is also known a Virtual address.
Virtual and physical addresses are the same in compile-time and load-time address-binding schemes. Virtual and physical addresses differ in
execution-time address-binding scheme.
The set of all logical addresses generated by a program is referred to as a logical address space. The set of all physical addresses corresponding
to these logical addresses is referred to as a physical address space.
The run-time mapping from virtual to physical address is done by the memory management unit (MMU) which is a hardware device. MMU uses
following mechanism to convert virtual address to physical address.

The value in the base register is added to every address generated by a user process which is treated as offset at the time it is sent to
memory. For example, if the base register value is 10000, then an attempt by the user to use address location 100 will be dynamically reallocated
to location 10100.

The user program deals with virtual addresses; it never sees the real physical addresses.

Swapping
Swapping is a mechanism in which a process can be swapped temporarily out of main memory to a backing store , and then brought back into
memory for continued execution.
Backing store is a usually a hard disk drive or any other secondary storage which fast in access and large enough to accommodate copies of all
memory images for all users. It must be capable of providing direct access to these memory images.
Major time consuming part of swapping is transfer time. Total transfer time is directly proportional to the amount of memory swapped. Let us
assume that the user process is of size 100KB and the backing store is a standard hard disk with transfer rate of 1 MB per second. The actual
transfer of the 100K process to or from memory will take
100KB / 1000KB per second
= 1/10 second
= 100 milliseconds

Memory Allocation
Main memory usually has two partitions

Low Memory -- Operating system resides in this memory.

High Memory -- User processes then held in high memory.


Operating system uses the following memory allocation mechanism.

S.N
.

Memory Allocation

Description

In this type of allocation, relocation-register scheme is used to


protect user processes from each other, and from changing
1

Single-partition allocation

operating-system code and data. Relocation register contains value


of smallest physical address whereas limit register contains range of
logical addresses. Each logical address must be less than the limit
register.
In this type of allocation, main memory is divided into a number of

Multiple-partition
allocation

fixed-sized partitions where each partition should contain only one


process. When a partition is free, a process is selected from the
input queue and is loaded into the free partition. When the process
terminates, the partition becomes available for another process.

Fragmentation
As processes are loaded and removed from memory, the free memory space is broken into little pieces. It happens after sometimes that
processes can not be allocated to memory blocks considering their small size and memory blocks remains unused. This problem is known as
Fragmentation.
Fragmentation is of two types

S.N
.

Fragmentation

Description

External

Total memory space is enough to satisfy a request or to reside a process

fragmentation

in it, but it is not contiguous so it can not be used.

Internal fragmentation

Memory block assigned to process is bigger. Some portion of memory is


left unused as it can not be used by another process.

External fragmentation can be reduced by compaction or shuffle memory contents to place all free memory together in one large block. To make
compaction feasible, relocation should be dynamic.

Paging
External fragmentation is avoided by using paging technique. Paging is a technique in which physical memory is broken into blocks of the same
size called pages (size is power of 2, between 512 bytes and 8192 bytes). When a process is to be executed, it's corresponding pages are loaded
into any available memory frames.
Logical address space of a process can be non-contiguous and a process is allocated physical memory whenever the free memory frame is
available. Operating system keeps track of all free frames. Operating system needs n free frames to run a program of size n pages.
Address generated by CPU is divided into
Page number (p) -- page number is used as an index into a page table which contains base address of each page in physical

memory.

Page offset (d) -- page offset is combined with base address to define the physical memory address.

Following figure show the paging table architecture.

Segmentation
Segmentation is a technique to break memory into logical pieces where each piece represents a group of related information. For example ,data
segments or code segment for each process, data segment for operating system and so on. Segmentation can be implemented using or without
using paging.
Unlike paging, segment are having varying sizes and thus eliminates internal fragmentation. External fragmentation still exists but to lesser extent.

Address generated by CPU is divided into


Segment number (s) -- segment number is used as an index into a segment table which contains base address of each segment in

physical memory and a limit of segment.

Segment offset (o) -- segment offset is first checked against limit and then is combined with base address to define the physical
memory address.

Deadlock
In an operating system, a deadlock is a situation which occurs when a process or thread enters a waiting state because
a resourcerequested is being held by another waiting process, which in turn is waiting for another resource. If a process
is unable to change its state indefinitely because the resources requested by it are being used by another waiting
process, then the system is said to be in a deadlock.

NECESSARY CONDITIONS
ALL of these four must happen simultaneously for a deadlock to occur:
DEADLOCKCHARACTERISATION
Mutual exclusion
One or more than one resource must be held by a process in a non-sharable (exclusive)
mode.
Hold and Wait
A process holds a resource while waiting for another resource.
No Preemption
There is only voluntary release of a resource - nobody else can make a process give up a
resource.
Circular Wait
Process A waits for Process B waits for Process C .... waits for Process A.

Prevention
Do not allow one of the four conditions to occur.
Mutual exclusion:
a) Automatically holds for printers and other non-sharables.
b) Shared entities (read only files) don't need mutual exclusion (and arent susceptible to
deadlock.)
c) Prevention not possible, since some devices are intrinsically non-sharable.
Hold and wait:
a) Collect all resources before execution.

b) A particular resource can only be requested when no others are being held. A sequence
of resources is always collected beginning with the same one.
c) Utilization is low, starvation possible.
No preemption:
a) Release any resource already being held if the process can't get an additional resource.
b) Allow preemption - if a needed resource is held by another process, which is also waiting
on some resource, steal it. Otherwise wait.
Circular wait:
a) Number resources and only request in ascending order.
b) EACH of these prevention techniques may cause a decrease in utilization and/or
resources. For this reason, prevention isn't necessarily the best technique.
c) Prevention is generally the easiest to implement.

Examples
Any deadlock situation can be compared to the classic "chicken or egg" problem.[4] It can be also
considered a paradoxical "Catch-22" situation.[5] A real world example would be an illogical statute passed
by the Kansas legislature in the early 20th century, which stated: [1][6]

When two trains approach each other at a crossing, both shall come to a full stop and
neither shall start up again until the other has gone.

A simple computer-based example is as follows. Suppose a computer has three CD drives and three
processes. Each of the three processes holds one of the drives. If each process now requests another
drive, the three processes will be in a deadlock. Each process will be waiting for the "CD drive released"
event, which can be only caused by one of the other waiting processes. Thus, it results in a circular chain.
Moving onto the source code level, a deadlock can occur even in the case of a single thread and one
resource (protected by a mutex). Assume there is a function func1() which does some work on the
resource, locking the mutex at the beginning and releasing it after it's done. Next, somebody creates a
different function func2() following that pattern on the same resource (lock, do work, release) but decides to
include a call to func1() to delegate a part of the job. What will happen is the mutex will be locked once
when enteringfunc2() and then again at the call to func1(), resulting in a deadlock if the mutex is
not reentrant (i.e. the plain "fast mutex" variety).

Necessary conditions
A deadlockers situation can arise if all of the following conditions hold simultaneously in a system: [1]
1. Mutual Exclusion: At least one resource must be held in a non-shareable mode.[1] Only one
process can use the resource at any given instant of time.

2. Hold and Wait or Resource Holding: A process is currently holding at least one resource and
requesting additional resources which are being held by other processes.
3. No Preemption: a resource can be released only voluntarily by the process holding it.
4. Circular Wait: A process must be waiting for a resource which is being held by another process,
which in turn is waiting for the first process to release the resource. In general, there is a set of
waiting processes, P = {P1, P2, ..., PN}, such that P1 is waiting for a resource held by P2, P2 is
waiting for a resource held by P3 and so on until PNis waiting for a resource held by P1.[1][7]
These four conditions are known as the Coffman conditions from their first description in a 1971 article
by Edward G. Coffman, Jr.[7] Unfulfillment of any of these conditions is enough to preclude a deadlock from
occurring.

Avoiding database deadlocks


An effective way to avoid database deadlocks is to follow this approach from the Oracle Locking Survival
Guide:
Application developers can eliminate all risk of enqueue deadlocks by ensuring that transactions requiring
multiple resources always lock them in the same order.[8]
This single sentence needs much explanation to understand the recommended solution. First it highlights
the fact that processes must be inside a transaction for deadlocks to happen. Note that some database
systems can be configured to cascade deletes which creates an implicit transaction which then can cause
deadlocks. Also some DBMSvendors offer row-level locking, a type of record locking which greatly reduces
the chance of deadlocks, as opposed to page level locking, which creates many times more locks. Second,
by "multiple resources" this means more than one row in one or more tables. An example of locking in the
same order would be to process all INSERTS first, all UPDATES second, and all DELETES last and within
processing each of these handle all parent table changes before children table changes; and process table
changes in the same order such as alphabetically or ordered by an ID or account number. Third,
eliminating all risk of deadlocks is difficult to achieve as the DBMS has automatic lock escalation features
that raise row level locks into page locks which can be escalated to table locks. Although the risk or chance
of experiencing a deadlock will not go to zero as deadlocks tend to happen more on large, high-volume,
complex systems, it can be greatly reduced and when required the software can be enhanced to retry
transactions when a deadlock is detected. Fourth, deadlocks can result in data loss if the software is not
developed to use transactions on every interaction with a DBMS and the data loss is difficult to locate and
creates unexpected errors and problems.
Deadlocks are a challenging problem to correct as they result in data loss, are difficult to isolate, create
unexpected problems, and are time consuming to fix. Modifying every section of software code in a large
system that access the database to always lock resources in the same order when the order is inconsistent
takes significant resources and testing to implement. That and the use of the strong word "dead" in front of
lock are some of the reasons why deadlocks have a "this is a big problem" reputation. [according to whom?]

Deadlock handling[edit]
Most current operating systems cannot prevent a deadlock from occurring. [1] When a deadlock occurs,
different operating systems respond to them in different non-standard manners. Most approaches work by
preventing one of the four Coffman conditions from occurring, especially the fourth one. [9] Major approaches
are as follows.

Ignoring deadlock[edit]
In this approach, it is assumed that a deadlock will never occur. This is also an application of the Ostrich
algorithm.[9][10] This approach was initially used by MINIX and UNIX.[7]This is used when the time intervals
between occurrences of deadlocks are large and the data loss incurred each time is tolerable.

Detection[edit]
Under deadlock detection, deadlocks are allowed to occur. Then the state of the system is examined to
detect that a deadlock has occurred and subsequently it is corrected. An algorithm is employed that tracks
resource allocation and process states, it rolls back and restarts one or more of the processes in order to
remove the detected deadlock. Detecting a deadlock that has already occurred is easily possible since the
resources that each process has locked and/or currently requested are known to the resource scheduler of
the operating system.[10]
Deadlock detection techniques include, but are not limited to, model checking. This approach constructs
a finite state-model on which it performs a progress analysis and finds all possible terminal sets in the
model. These then each represent a deadlock.
After a deadlock is detected, it can be corrected by using one of the following methods:
1. Process Termination: One or more processes involved in the deadlock may be aborted. We can
choose to abort all processes involved in the deadlock. This ensures that deadlock is resolved
with certainty and speed. But the expense is high as partial computations will be lost. Or, we can
choose to abort one process at a time until the deadlock is resolved. This approach has high
overheads because after each abort an algorithm must determine whether the system is still in
deadlock. Several factors must be considered while choosing a candidate for termination, such as
priority and age of the process.
2. Resource Preemption: Resources allocated to various processes may be successively
preempted and allocated to other processes until the deadlock is broken.

Prevention]
Main article: Deadlock prevention algorithms
Deadlock prevention works by preventing one of the four Coffman conditions from occurring.

Removing the mutual exclusion condition means that no process will have exclusive access to a
resource. This proves impossible for resources that cannot be spooled. But even with spooled

resources, deadlock could still occur. Algorithms that avoid mutual exclusion are called non-blocking
synchronization algorithms.

The hold and wait or resource holding conditions may be removed by requiring processes to
request all the resources they will need before starting up (or before embarking upon a particular set of
operations). This advance knowledge is frequently difficult to satisfy and, in any case, is an inefficient
use of resources. Another way is to require processes to request resources only when it has none.
Thus, first they must release all their currently held resources before requesting all the resources they
will need from scratch. This too is often impractical. It is so because resources may be allocated and
remain unused for long periods. Also, a process requiring a popular resource may have to wait
indefinitely, as such a resource may always be allocated to some process, resulting in resource
starvation.[1] (These algorithms, such as serializing tokens, are known as the all-or-none algorithms.)

The no preemption condition may also be difficult or impossible to avoid as a process has to be
able to have a resource for a certain amount of time, or the processing outcome may be inconsistent
or thrashing may occur. However, inability to enforce preemption may interfere with a priority algorithm.
Preemption of a "locked out" resource generally implies a rollback, and is to be avoided, since it is very
costly in overhead. Algorithms that allow preemption include lock-free and wait-free
algorithms and optimistic concurrency control.This condition may be removed as follows : If a process
holding some resources and requests for some another resource(s) which cannot be immediately
allocated to it, then by releasing all the currently being held resources of that process.

The final condition is the circular wait condition. Approaches that avoid circular waits include
disabling interrupts during critical sections and using a hierarchy to determine apartial ordering of
resources. If no obvious hierarchy exists, even the memory address of resources has been used to
determine ordering and resources are requested in the increasing order of the enumeration. [1] Dijkstra's
solution can also be used.

Avoidance[edit]
This section may contain content that is repetitive or redundant of text elsewhere in the
article. Please help improve it by merging similar text or removing repeated
statements. (September 2014)

Deadlock can be avoided if certain information about processes are available to the operating system
before allocation of resources, such as which resources a process will consume in its lifetime. For every
resource request, the system sees whether granting the request will mean that the system will enter
an unsafe state, meaning a state that could result in deadlock. The system then only grants requests that
will lead to safe states.[1] In order for the system to be able to determine whether the next state will be safe
or unsafe, it must know in advance at any time:

resources currently available

resources currently allocated to each process

resources that will be required and released by these processes in the future

It is possible for a process to be in an unsafe state but for this not to result in a deadlock. The notion of
safe/unsafe states only refers to the ability of the system to enter a deadlock state or not. For example, if a
process requests A which would result in an unsafe state, but releases B which would prevent circular wait,
then the state is unsafe but the system is not in deadlock.
One known algorithm that is used for deadlock avoidance is the Banker's algorithm, which requires
resource usage limit to be known in advance.[1] However, for many systems it is impossible to know in
advance what every process will request. This means that deadlock avoidance is often impossible.
Two other algorithms are Wait/Die and Wound/Wait, each of which uses a symmetry-breaking technique. In
both these algorithms there exists an older process (O) and a younger process (Y). Process age can be
determined by a timestamp at process creation time. Smaller timestamps are older processes, while larger
timestamps represent younger processes.

Wait/Die

Wound/Wait

O needs a resource held by Y

O waits

Y dies

Y needs a resource held by O

Y dies

Y waits

Another way to avoid deadlock is to avoid blocking, for example by using Non-blocking
synchronization or Read-copy-update.

File systems and operating systems


Many operating systems include support for more than one file system. Sometimes the OS and the file system are so
tightly interwoven it is difficult to separate out file system functions.
There needs to be an interface provided by the operating system software between the user and the file system. This
interface can be textual (such as provided by a command line interface, such as the Unix shell, or OpenVMS DCL) or
graphical (such as provided by a graphical user interface, such as file browsers). If graphical, the metaphor of the folder,
containing documents, other files, and nested folders is often used (see also: directory and folder).

Unix and Unix-like operating systems[edit]


Unix-like operating systems create a virtual file system, which makes all the files on all the devices appear to exist in a
single hierarchy. This means, in those systems, there is one root directory, and every file existing on the system is
located under it somewhere. Unix-like systems can use a RAM disk or network shared resource as its root directory.
Unix-like systems assign a device name to each device, but this is not how the files on that device are accessed.
Instead, to gain access to files on another device, the operating system must first be informed where in the directory
tree those files should appear. This process is called mounting a file system. For example, to access the files on a CD-

ROM, one must tell the operating system "Take the file system from this CD-ROM and make it appear under such-andsuch directory". The directory given to the operating system is called the mount point it might, for example,
be /media. The /media directory exists on many Unix systems (as specified in the Filesystem Hierarchy Standard)
and is intended specifically for use as a mount point for removable media such as CDs, DVDs, USB drives or floppy
disks. It may be empty, or it may contain subdirectories for mounting individual devices. Generally, only
the administrator (i.e. root user) may authorize the mounting of file systems.
Unix-like operating systems often include software and tools that assist in the mounting process and provide it new
functionality. Some of these strategies have been coined "auto-mounting" as a reflection of their purpose.

In many situations, file systems other than the root need to be available as soon as the operating system
has booted. All Unix-like systems therefore provide a facility for mounting file systems at boot time. System
administrators define these file systems in the configuration file fstab (vfstab in Solaris), which also indicates
options and mount points.

In some situations, there is no need to mount certain file systems at boot time, although their use may be
desired thereafter. There are some utilities for Unix-like systems that allow the mounting of predefined file systems
upon demand.

Removable media have become very common with microcomputer platforms. They allow programs and data
to be transferred between machines without a physical connection. Common examples include USB flash
drives, CD-ROMs, and DVDs. Utilities have therefore been developed to detect the presence and availability of a
medium and then mount that medium without any user intervention.

Progressive Unix-like systems have also introduced a concept called supermounting; see, for example, the
Linux supermount-ng project. For example, a floppy disk that has been supermounted can be physically removed
from the system. Under normal circumstances, the disk should have been synchronized and then unmounted
before its removal. Provided synchronization has occurred, a different disk can be inserted into the drive. The
system automatically notices that the disk has changed and updates the mount point contents to reflect the new
medium.

An automounter will automatically mount a file system when a reference is made to the directory atop which it
should be mounted. This is usually used for file systems on network servers, rather than relying on events such as
the insertion of media, as would be appropriate for removable media.

Linux[edit]
Linux supports many different file systems, but common choices for the system disk on a block device include the ext*
family (such as ext2, ext3 and ext4), XFS, JFS, ReiserFSand btrfs. For raw flash without a flash translation layer (FTL)
or Memory Technology Device (MTD), there is UBIFS, JFFS2, and YAFFS, among others. SquashFS is a common
compressed read-only file system.
Solaris[edit]
The Sun Microsystems Solaris operating system in earlier releases defaulted to (non-journaled or non-logging) UFS for
bootable and supplementary file systems. Solaris defaulted to, supported, and extended UFS.
Support for other file systems and significant enhancements were added over time, including Veritas Software Corp.
(Journaling) VxFS, Sun Microsystems (Clustering) QFS, Sun Microsystems (Journaling) UFS, and Sun Microsystems
(open source, poolable, 128 bit compressible, and error-correcting) ZFS.

Kernel extensions were added to Solaris to allow for bootable Veritas VxFS operation. Logging or Journaling was added
to UFS in Sun's Solaris 7. Releases of Solaris 10, Solaris Express, OpenSolaris, and other open source variants of the
Solaris operating system later supported bootable ZFS.
Logical Volume Management allows for spanning a file system across multiple devices for the purpose of adding
redundancy, capacity, and/or throughput. Legacy environments in Solaris may use Solaris Volume Manager (formerly
known as Solstice DiskSuite). Multiple operating systems (including Solaris) may use Veritas Volume Manager. Modern
Solaris based operating systems eclipse the need for Volume Management through leveraging virtual storage pools
in ZFS.
OS X[edit]
OS X uses a file system inherited from classic Mac OS called HFS Plus. Apple also uses the term "Mac OS Extended".
[15][16]

HFS Plus is a metadata-rich and case-preserving but (usually) case-insensitive file system. Due to the Unix roots of

OS X, Unix permissions were added to HFS Plus. Later versions of HFS Plus added journaling to prevent corruption of
the file system structure and introduced a number of optimizations to the allocation algorithms in an attempt to
defragment files automatically without requiring an external defragmenter.
Filenames can be up to 255 characters. HFS Plus uses Unicode to store filenames. On OS X, the filetype can come
from the type code, stored in file's metadata, or the filename extension.
HFS Plus has three kinds of links: Unix-style hard links, Unix-style symbolic links and aliases. Aliases are designed to
maintain a link to their original file even if they are moved or renamed; they are not interpreted by the file system itself,
but by the File Manager code in userland.
OS X also supported the UFS file system, derived from the BSD Unix Fast File System via NeXTSTEP. However, as
of Mac OS X Leopard, OS X could no longer be installed on a UFS volume, nor can a pre-Leopard system installed on a
UFS volume be upgraded to Leopard.[17] As of Mac OS X Lion UFS support was completely dropped.
Newer versions of OS X are capable of reading and writing to the legacy FAT file systems (16 & 32) common on
Windows. They are also capable of reading the newer NTFS file systems for Windows. In order to write to NTFS file
systems on OS X versions prior to 10.6 (Snow Leopard) third party software is necessary. Mac OS X 10.6 (Snow
Leopard) and later allows writing to NTFS file systems, but only after a non-trivial system setting change (third party
software exists that automates this).[18]
Finally, OS X supports reading and writing of the exFAT file system since Mac OS X Snow Leopard, starting from
version 10.6.5.[19]

PC-BSD[edit]
PC-BSD is a desktop version of FreeBSD, which inherits FreeBSD's ZFS support, similarly to FreeNAS. The new
graphical installer of PC-BSD can handle / (root) on ZFS andRAID-Z pool installs and disk encryption using Geli right
from the start in an easy convenient (GUI) way. The current PC-BSD 9.0+ 'Isotope Edition' has ZFS filesystem version 5
and ZFS storage pool version 28.

Plan 9[edit]
Plan 9 from Bell Labs treats everything as a file, and accessed as a file would be (i.e., no ioctl or mmap): networking,
graphics, debugging, authentication, capabilities, encryption, and other services are accessed via I-O operations on file
descriptors. The 9P protocol removes the difference between local and remote files.

These file systems are organized with the help of private, per-process namespaces, allowing each process to have a
different view of the many file systems that provide resources in a distributed system.
The Inferno operating system shares these concepts with Plan 9.

Microsoft Windows[edit]

Directory listing in a Windows command shell

Windows makes use of the FAT, NTFS, exFAT and ReFS file systems (the last of these is only supported and usable
inWindows Server 2012; Windows cannot boot from it).
Windows uses a drive letter abstraction at the user level to distinguish one disk or partition from another. For example,
thepath C:\WINDOWS represents a directory WINDOWS on the partition represented by the letter C. Drive C: is most
commonly used for the primary hard disk partition, on which Windows is usually installed and from which it boots. This
"tradition" has become so firmly ingrained that bugs exist in many applications which make assumptions that the drive
that the operating system is installed on is C. The use of drive letters, and the tradition of using "C" as the drive letter for
the primary hard disk partition, can be traced to MS-DOS, where the letters A and B were reserved for up to two floppy
disk drives. This in turn derived from CP/M in the 1970s, and ultimately from IBM's CP/CMS of 1967.
FAT[edit]
Main article: File Allocation Table
The family of FAT file systems is supported by almost all operating systems for personal computers, including all
versions of Windows and MS-DOS/PC DOS and DR-DOS. (PC DOS is an OEM version of MS-DOS, MS-DOS was
originally based on SCP's 86-DOS. DR-DOS was based on Digital Research's Concurrent DOS, a successor of CP/M86.) The FAT file systems are therefore well-suited as a universal exchange format between computers and devices of
most any type and age.
The FAT file system traces its roots back to an (incompatible) 8-bit FAT precursor in Standalone Disk BASIC and the
short-lived MDOS/MIDAS project.[citation needed]
Over the years, the file system has been expanded from FAT12 to FAT16 and FAT32. Various features have been
added to the file system including subdirectories, codepagesupport, extended attributes, and long filenames. Third
parties such as Digital Research have incorporated optional support for deletion tracking, and volume/directory/filebased multi-user security schemes to support file and directory passwords and permissions such as
read/write/execute/delete access rights. Most of these extensions are not supported by Windows.
The FAT12 and FAT16 file systems had a limit on the number of entries in the root directory of the file system and had
restrictions on the maximum size of FAT-formatted disks or partitions.

FAT32 addresses the limitations in FAT12 and FAT16, except for the file size limit of close to 4 GB, but it remains limited
compared to NTFS.
FAT12, FAT16 and FAT32 also have a limit of eight characters for the file name, and three characters for the extension
(such as .exe). This is commonly referred to as the 8.3 filename limit. VFAT, an optional extension to FAT12, FAT16 and
FAT32, introduced in Windows 95 and Windows NT 3.5, allowed long file names (LFN) to be stored in the FAT file
system in a backwards compatible fashion.
NTFS[edit]
Main article: NTFS
NTFS, introduced with the Windows NT operating system in 1993, allowed ACL-based permission control. Other
features also supported by NTFS include hard links, multiple file streams, attribute indexing, quota tracking, sparse files,
encryption, compression, and reparse points (directories working as mount-points for other file systems, symlinks,
junctions, remote storage links).
exFAT[edit]
Main article: exFAT
exFAT is a proprietary and patent-protected file system with certain advantages over NTFS with regard to file system
overhead.
exFAT is not backward compatible with FAT file systems such as FAT12, FAT16 or FAT32. The file system is supported
with newer Windows systems, such as Windows Server 2003, Windows Vista, Windows 2008, Windows 7, Windows 8,
and more recently, support has been added for Windows XP.[20]
exFAT is supported in Mac OS X starting with version 10.6.5 (Snow Leopard). [19] Support in other operating systems is
sparse since Microsoft has not published the specifications of the file system and implementing support for exFAT
requires a license.

OpenVMS[edit]
Main article: Files-11

MVS [IBM Mainframe][edit]


Main article: MVS MVS filesystem

Other file systems[edit]

The Prospero File System is a file system based on the Virtual System Model. [21] The system was created by
Dr. B. Clifford Neuman of the Information Sciences Institute at the University of Southern California. [22]

RSRE FLEX file system - written in ALGOL 68

The file system of the Michigan Terminal System (MTS) is interesting because: (i) it provides "line files" where
record lengths and line numbers are associated as metadata with each record in the file, lines can be added,
replaced, updated with the same or different length records, and deleted anywhere in the file without the need to
read and rewrite the entire file; (ii) using program keys files may be shared or permitted to commands and
programs in addition to users and groups; and (iii) there is a comprehensive file locking mechanism that protects
both the file's data and its metadata.[23][24]

Вам также может понравиться