CS6401-OS
CS6401-OS
OBJECTIVES:
Mass Storage Structure- Overview, Disk Scheduling and Management; File System Storage-File
Concepts, Directory and Disk Structure, Sharing and Protection; File System Implementation-
File System Structure, Directory Structure, Allocation Methods, Free Space Management, I/O
Systems.
TOTAL: 45 PERIODS
OUTCOMES:
TEXT BOOK:
1. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne, “Operating System Concepts”, 9 th
Edition, John Wiley and Sons Inc., 2012.
REFERENCES:
1. William Stallings, “Operating Systems – Internals and Design Principles”, 7th Edition,
Prentice Hall,2011.
5. http://nptel.ac.in/.
UNIT – I OPERATING SYSTEMS OVERVIEW
Computer System Overview-Basic Elements, Instruction Execution, Interrupts, Memory
Hierarchy, Cache Memory, Direct Memory Access, Multiprocessor and Multicore
Organization. Operating system overview-objectives and functions, Evolution of Operating
System.- Computer System Organization-Operating System Structure and Operations-
System Calls, System Programs, OS Generation and System Boot.
The hardware - the central processing unit (CPU), the memory, and the
Input/output (I/O) devices-provides the basic computing resources.
The application programs- such as word processors, spreadsheets, compilers,
and web browsers- define the ways in which these resources are used to
solve the computing problems of the users.
An operating system is similar to a government. The OS simply provides an
environment within which other programs can do useful work.
Abstract view of the components of a computer system.
Operating system can be viewed as a resource allocator.
The OS acts as the manager of the resources ( such as CPU time, memory space, file
storage space, I/O devices) and allocates them to specific programs and users as
necessary for tasks.
An operating system is a control program. It controls the execution of user programs
to prevent errors and improper use of computer.
1.1.1 Mainframe Systems
Early computers were physically enormous machines run from a console.
The common input devices were card readers and tape drives.
The common output devices were line printers, tape drives, and card punches.
The user did not interact directly with the computer systems.
Rather, the user prepared a job - which consisted of the program, the data, and some
control information about the nature of the job (control cards)-and submitted it to the
computer operator.
The job was usually in the form of punch cards.
The operating system in these early computers was fairly simple.
Its major task was to transfer control automatically from one job to the next.
The operating system was always resident in memory
(vi) Networking
A distributed system is a collection of processors that do not share memory,
peripheral devices, or a clock.
Instead, each processor has its own local memory and clock, and the
processors communicate with one another through various communication lines,
such as high-speed buses or networks.
The processors in the system are connected through a communication network,
which can be configured in a number of different ways.
(vii) Protection System
Various processes must be protected from one another's activities. For that purpose,
mechanisms ensure that the files, memory segments, CPU, and other resources
can be operated on by only those processes that have gained proper authorization
from the operating system.
Protection is any mechanism for controlling the access of programs, processes, or
users to the resources defined by a computer system.
Protection can improve reliability by detecting latent errors at the interfaces between
component subsystems.
(viii) Command-Interpreter System
One of the most important systems programs for an operating system is the command
interpreter.
It is the interface between the user and the operating system.
Some operating systems include the command interpreter in the kernel. Other
operating systems, such as MS-DOS and UNIX, treat the command interpreter as a
special program that is running when a job is initiated, or when a user first logs on
(on time-sharing systems).
Many commands are given to the operating system by control statements.
When a new job is started in a batch system, or when a user logs on to a time-
shared system, a program that reads and interprets control statements is executed
automatically.
This program is sometimes called the control-card interpreter or the command-
line interpreter, and is often known as the shell.
volatile
1.3.2 I/O modules
communications equipment
terminals
1.3.3 System bus
communication among processors, memory, andI/O modules.
1.4 INTERRUPTS
An interrupt is a signal from a device attached to a computer or from a program within
the computer that causes the main program that operates the computer (the operating
system) to stop and figure out what to do next. Almost all personal (or larger) computers
today are interrupt-driven - that is, they start down the list of computer instruction s in
one program (perhaps an application such as a word processor) and keep running the
instructions until either (A) they can't go any further or (B) an interrupt signal is sensed.
Basically, a single computer can perform only one computer instruction at a time. But,
because it can be interrupted, it can take turns in which programs or sets of instructions
that it performs. This is known as multitasking. It allows the user to do a number of
different things at the same time. The computer simply takes turns managing the
programs that the user effectively starts. Of course, the computer operates at speeds that
make it seem as though all of the user's tasks are being performed at the same time. (The
computer's operating system is good at using little pauses in operations and user thinks
time to work on other programs.)
An operating system usually has some code that is called an interrupt handler. The
interrupt handler prioritizes the interrupts and saves them in a queue if more than one is
waiting to be handled. The operating system has another little program, sometimes called
a scheduler that figures out which program to give control to next.
In general, there are hardware interrupts and software interrupts. A hardware interrupt
occurs, for example, when an I/O operation is completed such as reading some data into
the computer from a tape drive. A software interrupt occurs when an application program
terminates or requests certain services from the operating system. In a personal computer,
a hardware interrupt request ( IRQ ) has a value associated with it that associates it with a
particular device.
This feature is useful any time the CPU cannot keep up with the rate of data transfer, or
where the CPU needs to perform useful work while waiting for a relatively slow I/O data
transfer. Many hardware systems use DMA, including disk drive controllers, graphics
cards, network cards and sound cards.
DMA is also used for intra-chip data transfer in multi-core processors. Computers that
have DMA channels can transfer data to and from devices with much less CPU overhead
than computers without DMA channels. Similarly, a processing element inside a multi-
core processor can transfer data to and from its local memory without occupying its
processor time, allowing computation and data transfer to proceed in parallel.
1.7.1.1Burst mode
An entire block of data is transferred in one contiguous sequence. Once the DMA
controller is granted access to the system bus by the CPU, it transfers all bytes of
data in the data block before releasing control of the system buses back to the
CPU, but renders the CPU inactive for relatively long periods of time. The mode
is also called "Block Transfer Mode". It is also used to stop unnecessary data.
Usage
Users of a computer system:
Programs - use memory, use CPU time, use I/O devices
Human users
Programmers - use program development tools such as debuggers, editors end
users - use application programs, e.g. Internet explorer
Computer system
hardware + software
OS is a part of the computer software, it is a program. It is a very special program, that is
the first to be executed when the computer is switched on, and is supposed to control and
support the execution of other programs and the overall usage of the computer system.
Control
The operating system controls the usage of the computer resources - hardware devices
and software utilities. We can think of an operating system as a Resource Manager. Here
are some of the resources managed by the OS:
Processors,
Main memory,
Secondary Memory,
Peripheral devices,
Information.
Support
The operating system provides a number of services to assist the users of the
computer system:
For the programmers:
Utilities - debuggers, editors, file management, etc.
For the end users - provides the interface to the application programs
For programs - loads instructions and data into memory, prepares I/O devises for
usage, handles interrupts and error conditions.
1.10 EVOLUTION OF OPERATING SYSTEM
1.10.1 Serial Processing - 1940’s – 1950’s programmer interacted directly with hardware. No
operating system.
Problems
Setup Time- Setup included loading the compiler, source program, saving
compiled program, and loading and linking. If an error occurred - start over.
Jobs were submitted on cards or tape to an operator who batches jobs together
sequentially. The program that controls the execution of the jobs was called monitor - a simple
version of an operating system. The interface to the monitor was accomplished through Job
Control Language (JCL). For example, a JCL request could be to run the compiler for a
particular programming language, then to link and load the program, then to run the user
program.
Hardware features:
Memory protection: do not allow the memory area containing the monitor to be altered
Problems:
Bad utilization of CPU time - the processor stays idle while I/O devices are in use.
More than one program resides in the main memory. While a program A uses an I/O device the
processor does not stay idle, instead it runs another program B.
New features:
Memory management - to have several jobs ready to run, they must be kept in main
memory
Time-sharing systems: Several (human) users use the computer system interactively.
Characteristics:
1. Program execution:
The system must be able to load a program into memory and to run that
program. The program must be able to end its execution, either normally or abnormally
(indicating error).
2. I/O operations:
A running program may require I/O. This I/O may involve a file or an I/O device.
3. File-system manipulation:
The program needs to read, write, create and delete files.
4. Communications :
In many circumstances, one process needs to exchange information with another
process. Such communication can occur in two major ways. The first takes place
between processes that are executing on the same computer; the second takes place
between processes that are executing on different computer systems that are tied
together by a computer network.
5. Error detection:
The operating system constantly needs to be aware of possible errors. Errors may
occur in the CPU and memory hardware (such as a memory error or a power failure), in
I/O devices (such as a parity error on tape, a connection failure on a network, or lack of
paper in the printer), and in the user program (such as an arithmetic overflow, an attempt
to access an illegal memory location, or a 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.
6. Resource allocation:
Different types of resources are managed by the Os.
When there are multiple users or multiple jobs running at the same time, resources
must be allocated to each of them.
7. Accounting:
We want to keep track of which users use how many and which kinds of
computer resources. This record keeping may be used for accounting or simply for
accumulating usage statistics.
8. Protection:
The owners of information stored in a multiuser computer system may want to
control use of that information. Security of the system is also important.
1.10.6 CP derivatives
1. CP
2. CP-VM
3. CP/M
1. CP/M-86
2. DOS
3. DRDOS
1. FreeDOS
4. Microsoft Windows
1. Windows 3.x
2. Windows 95/98/Me
3. Windows Xp
4. Windows Vista
5. Windows 7
6. windows 8
1.10.7 MULTICS derivatives
1. UNIX
Unix V5 (SCO Unix)
Modern Unix (Solaris / BSD )
FreeBSD
OpenBSD
2. Xenix
3. Linux
4. Plan 9 jim bading tahaha
Inferno to hell
5. QNX
6. VSTa
7. Mac OSX
8. MIPS RISC/os
9. RISC iX
1.10.8 VMS derivatives
1. VMS
1. OpenVMS
2. OS/2
1. eComStation
3. Microsoft Windows =rude-magic!
1. ReactOS
1.10.9 MacOS derivatives
1. Mac OS
1. Mac OS 9
1.10.10 Cambridge CAP Computer derivatives
1. KeyKOS
1. EROS
2. Coyotos
3. CapROS
1.10.11 IBSYS derivatives
1. OS/360
2. OS/400
1.10.12 AmigaOS Derivatives
1. AmigaOS
2. AROS
1. AmigaOS 4.x
2. MorphOS
1.10.13 Novel Operating Systems
1. Grasshopper
2. ITS
3. BeOS
At the very least, we need two separate modes of operation: user mode and kernel mode
(also called supervisor mode, system mode, or privileged mode).
A bit, called the mode bit, is added to the hardware of the computer to indicate the
current mode: kernel (0) or user (1). With the mode bit, we can distinguish between a task
that is executed on behalf of the operating system and one that is executed on behalf of
the user.
1.11.2.2Timer
We cannot allow a user program to get stuck in an infinite loop or to fail to call system
services and never return control to the operating system.
To accomplish this goal, we can use a timer. A timer can be set to interrupt the computer
after a specified period. The period may be fixed (for example, 1/60 second) or variable
(for example, from 1 millisecond to 1 second).
A variable timer is generally implemented by a fixed-rate clock and a counter.
The operating system sets the counter. Every time the clock ticks, the counter is
decremented. When the counter reaches 0, an interrupt occurs. For instance, a 10-bit
counter with a 1-millisecond clock allows interrupts at intervals from 1 millisecond to
1,024 milliseconds, in steps of 1 millisecond.
1.13 SYSTEM CALLS
System calls provide the interface between a process and the operating system.
These calls are generally available as assembly-language instructions.
System calls can be grouped roughly into five major categories:
1. Process control
2. file management
3. device management
4. information maintenance
5. communications.
1. Process Control
end,abort
load, execute
Create process and terminate process
get process attributes and set process attributes.
wait for time, wait event, signal event
Allocate and free memory.
2. File Management
Create file, delete file
Open , close
Read, write, reposition
Get file attributes, set file attributes.
3. Device Management
Request device, release device.
Read, write, reposition
Get device attribtues, set device attributes
Logically attach or detach devices
4. Information maintenance
Get time or date, set time or date
Get system data, set system data
Get process, file, or device attributes
Set process, file or device attributes
5. Communications
Create, delete communication connection
Send, receive messages
Transfer status information
Attach or detach remote devices
Two types of communication models
(a) Message passing model
(b) Shared memory model
1.14 SYSTEM PROGRAMS
System programs provide a convenient environment for program development and
execution.
They can be divided into several categories:
1. File management: These programs create, delete, copy, rename, print, dump, list and
generally manipulate files and directories.
2. Status information: The status such as date, time, amount of available memory
or diskspace, number of users or similar status information.
3. File modification: Several text editors may be available to create and modify the
content of files stored on disk or tape.
4. Programming-language support: Compilers, assemblers, and interpreters for
common programming languages are often provided to the user with the operating system.
5. Program loading and execution: The system may provide absolute loaders,
relocatable loaders, linkage editors, and overlay loaders.
6. Communications: These programs provide the mechanism for creating virtual
connections among processes, users, and different computer systems. (email, FTP, Remote log
in)
7. Application programs: Programs that are useful to solve common problems, or
to perform common operations.
Eg. Web browsers, database systems.
2.1 PROCESSES
Even though in actuality there are many processes running at once, the OS gives each process the
illusion that it is running alone.
Virtual time: The time used by just these processes. Virtual time progresses at a rate
independent of other processes. Actually, this is false, the virtual time is typically
incremented a little during systems calls used for process switching; so if there are more
other processors more ``overhead'' virtual time occurs.
Virtual memory: The memory as viewed by the process. Each process typically believes
it has a contiguous chunk of memory starting at location zero. Of course this can't be true
of all processes (or they would be using the same memory) and in modern systems it is
actually true of no processes (the memory assigned is not contiguous and does not
include location zero).
Think of the individual modules that are input to the linker. Each numbers its addresses
from zero; the linker eventually translates these relative addresses into absolute
addresses. That is the linker provides to the assembler a virtual memory in which
addresses start at zero.
Virtual time and virtual memory are examples of abstractions provided by the operating system
to the user processes so that the latter ``sees'' a more pleasant virtual machine than actually
exists.
Modern general purpose operating systems permit a user to create and destroy processes.
In unix this is done by the fork system call, which creates a child process, and the exit
system call, which terminates the current process.
After a fork both parent and child keep running (indeed they have the same program text)
and each can fork off other processes.
A process tree results. The root of the tree is a special process created by the OS during
startup.
A process can choose to wait for children to terminate. For example, if C issued a wait()
system call it would block until G finished.
Old or primitive operating system like MS-DOS are not multiprogrammed so when one process
starts another, the first process is automatically blocked and waits until the second is finished.
Job Queue
Ready Queue
Device Queue
As processes enter the system, they are put into a job queue.
The processes that are residing in main memory and are ready and waiting to execute
are kept on a list called the ready queue.
The list of processes waiting for an I/O device is kept in a device queue for that
particular device.
A new process is initially put in the ready queue. It waits in the ready queue until it is
selected for execution (or dispatched).
Once the process is assigned tothe CPU and is executing, one of several events could
occur:
o The process could issue an I/O request, and then be placed in an I/O
queue.
o The process could create a new subprocess and wait for its termination.
The process could be removed forcibly from the CPU, as a result of an interrupt, and be
put back in the ready Queue.
Schedulers
A process migrates between the various scheduling queues throughout its lifetime.
The operating system must select, for scheduling purposes, processes from these queues
in some fashion.
The selection process is carried out by the appropriate scheduler.
There are three different types of schedulers.They are:
1. Long-term Scheduler or Job Scheduler
2. Short-term Scheduler or CPU Scheduler
3. Medium term Scheduler
The long-term scheduler, or job scheduler, selects processes from this pool and loads them
into memory for execution. It is invoked very in frequently. It controls the degree of
multiprogramming.
The short-term scheduler, or CPU scheduler, selects from among the processes that are
ready to execute, and allocates the CPU to one of them. It is invoked very frequently.
o Processes can be described as either I/O bound or CPU bound.
o An I\O-bound process spends more of its time doing I/O than it spends doing
computations.
o A CPU-bound process, on the other hand, generates I/O requests infrequently,
using more of its time doing computation than an I/O-bound process uses.
o The system with the best performance will have a combination of CPU-bound and
I/O-bound processes.
The parent waits until some or all of its children have terminated.
There are also two possibilities in terms of the address space of the new process:
The child has exceeded its usage of some of the resources that it has been
allocated.
The parent is exiting, and the operating system does not allow a child to
continue if its parent terminates. On such systems, if a process
terminates (either normally or abnormally), then all its children must also
be terminated. This phenomenon, referred to as cascading termination,
is normally initiated by the operating system.
If the process has multiple threads of control, it can do more than one task at a time.
2.5.1 Benefits of multithreaded programming
Responsiveness
Resource Sharing
Economy
Utilization of MP Architectures
Supported above the kernel and implemented by a thread library at the user level.
When a user thread performs a blocking system call ,it will cause the entire
process to block even if other threads are available to run within the application.
2.5.2.2.Kernel threads
When a kernel thread performs a blocking system call ,the kernel schedules
another thread in the application for execution.
Example: Windows NT, Windows 2000 , Solaris 2,BeOS and Tru64 UNIX
support kernel threads.
A recent trend in computer architecture is to produce chips with multiple cores, or CPUs
on a single chip.
A multi-threaded application running on a traditional single-core chip would have to
interleave the threads.
On a multi-core chip, however, the threads could be spread across the available cores,
allowing true parallel processing.
For operating systems, multi-core chips require new scheduling algorithms to make better
use of the multiple cores available.
As multi-threading becomes more pervasive and more important (thousands instead of
tens of threads), CPUs have been developed to support more simultaneous threads per
core in hardware.
For application programmers, there are five areas where multi-core chips present new
challenges:
In practice no program is ever divided up solely by one or the other of these, but instead
by some sort of hybrid combination.
1. Many-to-One:
Many user-level threads mapped to single kernel thread.
Used on systems that do not support kernel threads.
2.One-to-One:
Each user-level thread maps to a kernel thread.
Examples
- Windows 95/98/NT/2000
- OS/2
3. Many-to-Many Model:
Allows many user level threads to be mapped to many kernel threads.
Allows the operating system to create a sufficient number of kernel threads.
Solaris 2
Windows NT/2000
2.6.1 Pthreads
The POSIX standard ( IEEE 1003.1c ) defines the specification for pThreads, not the
implementation.
pThreads are available on Solaris, Linux, Mac OSX, Tru64, and via public domain
shareware for Windows.
Global variables are shared amongst all threads.
One thread can wait for the others to rejoin before continuing.
pThreads begin execution in a specified function, in this example the runner( ) function:
The creation of new Threads requires Objects that implement the Runnable Interface,
which means they contain a method "public void run( )" . Any descendant of the Thread
class will naturally contain such a method. ( In practice the run( ) method must be
overridden / provided for the thread to have any practical functionality. )
Creating a Thread Object does not start the thread running - To do that the program must
call the Thread's "start( )" method. Start( ) allocates and initializes memory for the
Thread, and then calls the run( ) method. ( Programmers do not call run( ) directly. )
Because Java does not support global variables, Threads must be passed a reference to a
shared Object in order to share data, in this example the "Sum" Object.
Note that the JVM runs on top of a native OS, and that the JVM specification does not
specify what model to use for mapping Java threads to kernel threads. This decision is
JVM implementation dependant, and may be one-to-one, many-to-many, or many to one..
( On a UNIX system the JVM normally uses PThreads and on a Windows system it
normally uses windows threads. )
2.7.1 Background
Producer code
item nextProduced;
while( true ) {
/* Produce an item and store it in nextProduced */
nextProduced = makeNewItem( . . . );
Consumer code
item nextConsumed;
while( true ) {
The only problem with the above code is that the maximum number of items which can
be placed into the buffer is BUFFER_SIZE - 1. One slot is unavailable because there
always has to be a gap between the producer and the consumer.
The particular problem above comes from the producer executing "counter++" at the
same time the consumer is executing "counter--". If one process gets part way through
making the update and then the other process butts in, the value of counter can get left in
an incorrect state.
But, you might say, "Each of those are single instructions - How can they get
interrupted halfway through?" The answer is that although they are single instructions in
C++, they are actually three steps each at the hardware level:
(1) Fetch counter from memory into a register,
(2) increment or decrement the register, and
(3) Store the new value of counter back to memory. If the instructions from the two
processes get interleaved, there could be serious problems, such as illustrated by the
following:
2.8 CRITICAL-SECTION PROBLEM
o Only one process in the group can be allowed to execute in their critical section at
any one time. If one process is already executing their critical section and another
process wishes to do so, then the second process must be made to wait until the
first process has completed their critical section work.
o The code preceding the critical section, and which controls access to the critical
section, is termed the entry section. It acts like a carefully controlled locking door.
o The code following the critical section is termed the exit section. It generally
releases the lock on someone else's door, or at least lets the world know that they
are no longer in their critical section.
o The rest of the code not included in either the critical section or the entry or exit
sections is termed the remainder section.
A solution to the critical section problem must satisfy the following three conditions:
1. Mutual Exclusion - Only one process at a time can be executing in their critical
section.
2. Progress - If no process is currently executing in their critical section, and one or
more processes want to execute their critical section, then only the processes not
in their remainder sections can participate in the decision, and the decision cannot
be postponed indefinitely. ( i.e. processes cannot be blocked forever waiting to get
into their critical sections. )
3. Bounded Waiting - There exists a limit as to how many other processes can get
into their critical sections after a process requests entry into their critical section
and before that request is granted. ( I.e. a process requesting entry into their
critical section will get a turn eventually, and there is a limit as to how many other
processes get to go first. )
We assume that all processes proceed at a non-zero speed, but no assumptions can be
made regarding the relative speed of one process versus another.
Kernel processes can also be subject to race conditions, which can be especially
problematic when updating commonly shared kernel data structures such as open file
tables or virtual memory management. Accordingly kernels can take on one of two
forms:
The hardware solutions presented above are often difficult for ordinary programmers to
access, particularly on multi-processor machines, and particularly because they are often
platform-dependent.
Therefore most systems offer a software API equivalent called mutex locks or simply
mutexes. ( For mutual exclusion )
The terminology when using mutexes is to acquire a lock prior to entering a critical
section, and to release it when exiting.
Just as with hardware locks, the acquire step will block the process if the lock is in use by
another process, and both the acquire and release operations are atomic.
Acquire and release can be implemented as shown here, based on a boolean variable
"available":
One problem with the implementation shown here, ( and in the hardware solutions
presented earlier ), is the busy loop used to block processes in the acquire phase. These
types of locks are referred to as spinlocks, because the CPU just sits and spins while
blocking the process.
Spinlocks are wasteful of cpu cycles, and are a really bad idea on single-cpu single-
threaded machines, because the spinlock blocks the entire computer, and doesn't allow
any other process to release the lock. ( Until the scheduler kicks the spinning process off
of the cpu. )
On the other hand, spinlocks do not incur the overhead of a context switch, so they are
effectively used on multi-threaded machines when it is expected that the lock will be
released after a short time.
2.10 SEMAPHORES
A more robust alternative to simple mutexes is to use semaphores, which are integer
variables for which only two (atomic ) operations are defined, the wait and signal
operations, as shown in the following figure.
Note that not only must the variable-changing steps ( S-- and S++ ) be indivisible, it is
also necessary that for the wait operation when the test proves false that there be no
interruptions before S gets decremented. It IS okay, howeve
which prevents the system from hanging forever.
o Binary semaphores can take on one of two values, 0 or 1. They can be used to
solve the critical section problem as described above, and can be used as mutexes
on systems that do not provide a separate mutex mechanism.. The use of mutexes
for this purpose is shown in Figure below.
Semaphores can also be used to synchronize certain operations between processes. For
example, suppose it is important that process P1 execute statement S1 before process P2
executes statement S2.
First we create a semaphore named synch that is shared by the two processes, and
initialize it to zero.
Then in process P1 we insert the code:
S1;
signal( synch );
wait( synch );
S2;
Because synch was initialized to 0, process P2 will block on the wait until after P1
executes the call to signal.
The big problem with semaphores as described above is the busy loop in the wait call,
which consumes CPU cycles without doing any useful work. This type of lock is known
as a spinlock, because the lock just sits there and spins while it waits. While this is
generally a bad thing, it does have the advantage of not invoking context switches, and so
it is sometimes used in multi-processing systems when the wait time is expected to be
short - One thread spins on one processor while another completes their critical section
on another processor.
An alternative approach is to block a process when it is forced to wait for an available
semaphore, and swap it out of the CPU. In this implementation each semaphore needs to
maintain a list of processes that are blocked waiting for it, so that one of the processes
can be woken up and swapped back in when the semaphore becomes available. (Whether
it gets swapped back into the CPU immediately or whether it needs to hang out in the
ready queue for a while is a scheduling problem.)
The new definition of a semaphore and the corresponding wait and signal operations are
shown as follows:
2.10.3 Deadlocks and Starvation
One important problem that can arise when using semaphores to block processes waiting
for a limited resource is the problem of deadlocks, which occur when multiple processes
are blocked, each waiting for a resource that can only be freed by one of the other (
blocked ) processes, as illustrated in the following example.
Another problem to consider is that of starvation, in which one or more processes gets
blocked forever, and never get a chance to take their turn in the critical section. For
example, in the semaphores above, we did not specify the algorithms for adding
processes to the waiting queue in the semaphore in the wait( ) call, or selecting one to be
removed from the queue in the signal( ) call. If the method chosen is a FIFO queue, then
every process will eventually get their turn, but if a LIFO queue is implemented instead,
then the first process to start waiting could starve.
2.11 MONITORS
Semaphores can be very useful for solving concurrency problems, but only if
programmers use them properly. If even one process fails to abide by the proper use of
semaphores, either accidentally or deliberately, then the whole system breaks down. (And
since concurrency problems are by definition rare events, the problem code may easily go
unnoticed and/or be heinous to debug.)
For this reason a higher-level language construct has been developed, called monitors.
In order to fully realize the potential of monitors, we need to introduce one additional
new data type, known as a condition.
A variable of type condition has only two legal operations, wait and
signal. I.e. if X was defined as type condition, then legal operations would
be X.wait( ) and X.signal( )
The wait operation blocks a process until some other process calls signal,
and adds the blocked process onto a list associated with that condition.
The signal process does nothing if there are no processes waiting on that
condition. Otherwise it wakes up exactly one process from the condition's
list of waiting processes. (Contrast this with counting semaphores, which
always affect the semaphore on a signal call.)
Signal and wait - When process P issues the signal to wake up process Q, P then waits, either
for Q to leave the monitor or on some other condition.
Signal and continue - When P issues the signal, Q waits, either for P to exit the monitor or for
some other condition.
There are arguments for and against either choice. Concurrent Pascal offers a third alternative -
The signal call causes the signaling process to immediately exit the monitor, so that the waiting
process can then wake up and proceed.
Almost all programs have some alternating cycle of CPU number crunching and waiting
for I/O of some kind. ( Even a simple fetch from memory takes a long time relative to
CPU speeds. )
In a simple system running a single process, the time spent waiting for I/O is wasted, and
those CPU cycles are lost forever.
A scheduling system allows one process to use the CPU while another is waiting for I/O,
thereby making full use of otherwise lost CPU cycles.
The challenge is to make the overall system as "efficient" and "fair" as possible, subject
to varying and often dynamic conditions, and where "efficient" and "fair" are somewhat
subjective terms, often subject to shifting priority policies.
Almost all processes alternate between two states in a continuing cycle, as shown in
Figure below :
Whenever the CPU becomes idle, it is the job of the CPU Scheduler ( a.k.a. the short-
term scheduler ) to select another process from the ready queue to run next.
The storage structure for the ready queue and the algorithm used to select the next
process are not necessarily a FIFO queue. There are several alternatives to choose from,
as well as numerous adjustable parameters for each algorithm.
2.12.4 Dispatcher
The dispatcher is the module that gives control of the CPU to the process selected by the
scheduler. This function involves:
o Switching context.
o Switching to user mode.
o Jumping to the proper location in the newly loaded program.
The dispatcher needs to be as fast as possible, as it is run on every context switch. The
time consumed by the dispatcher is known as dispatch latency.
2.12.5 Scheduling Algorithms
The following subsections will explain several common scheduling strategies, looking at
only a single CPU burst each for a small number of processes. Obviously real systems
have to deal with a lot more simultaneous processes executing their CPU-I/O burst
cycles.
FCFS is very simple - Just a FIFO queue, like customers waiting in line at the
bank or the post office or at a copying machine.
Unfortunately, however, FCFS can yield some very long average wait times,
particularly if the first process to get there takes a long time. For example,
consider the following three processes:
In the first Gantt chart below, process P1 arrives first. The average waiting time
for the three processes is ( 0 + 24 + 27 ) / 3 = 17.0 ms.
In the second Gantt chart below, the same three processes have an average wait
time of ( 0 + 3 + 6 ) / 3 = 3.0 ms. The total run time for the three bursts is the
same, but in the second case two of the three finish much quicker, and the other
process is only delayed by a short amount.
The idea behind the SJF algorithm is to pick the quickest fastest little job that
needs to be done, get it out of the way first, and then pick the next smallest fastest
job to do next.
Technically this algorithm picks a process based on the next shortest CPU burst,
not the overall process time.
For example, the Gantt chart below is based upon the following CPU burst times,
( and the assumption that all jobs arrive at the same time. )
Priority scheduling is a more general case of SJF, in which each job is assigned a
priority and the job with the highest priority gets scheduled first. (SJF uses the
inverse of the next expected burst time as its priority - The smaller the expected
burst, the higher the priority. )
Note that in practice, priorities are implemented using integers within a fixed
range, but there is no agreed-upon convention as to whether "high" priorities use
large numbers or small numbers.
For example, the following Gantt chart is based upon these process burst times
and priorities, and yields an average waiting time of 8.2 ms:
Round robin scheduling is similar to FCFS scheduling, except that CPU bursts are
assigned with limits called time quantum.
When a process is given the CPU, a timer is set for whatever value has been set
for a time quantum.
o If the process finishes its burst before the time quantum timer expires, then
it is swapped out of the CPU just like the normal FCFS algorithm.
o If the timer goes off first, then the process is swapped out of the CPU and
moved to the back end of the ready queue.
The ready queue is maintained as a circular queue, so when all processes have had
a turn, then the scheduler gives the first process another turn, and so on.
RR scheduling can give the effect of all processors sharing the CPU equally,
although the average wait time can be longer than with other scheduling
algorithms. In the following example the average wait time is 5.66 ms.
In general, turnaround time is minimized if most processes finish their next cpu burst
within one time quantum. For example, with three processes of 10 ms bursts each, the
average turnaround time for 1 ms quantum is 29, and for 10 ms quantum it reduces to 20.
However, if it is made too large, then RR just degenerates to FCFS. A rule of thumb is
that 80% of CPU bursts should be smaller than the time quantum.
When processes can be readily categorized, then multiple separate queues can be
established, each implementing whatever scheduling algorithm is most appropriate for
that type of job, and/or with different parametric adjustments.
Scheduling must also be done between queues, that is scheduling one queue to get time
relative to other queues. Two common options are strict priority ( no job in a lower
priority queue runs until all higher priority queues are empty ) and round-robin ( each
queue gets a time slice in turn, possibly of different sizes. )
Note that under this algorithm jobs cannot switch from queue to queue - Once they are
assigned a queue, that is their queue until they finish
2.13 DEADLOCK
Definition: A process requests resources. If the resources are not available at that time ,the
process enters a wait state. Waiting processes may never change state again because the
resources they have requested are held by other waiting processes. This situation is called a
deadlock.
A process must request a resource before using it, and must release resource after using it.
1. Request: If the request cannot be granted immediately then the requesting process
must wait until it can acquire the resource.
2. Use: The process can operate on the resource
3. Release: The process releases the resource.
Resource instances
One instance of resource type R1,Two instance of resource type R2,One instance of
resource type R3,Three instances of resource type R4.
Process states
Process P1 is holding an instance of resource type R2, and is waiting for an instance of
resource type R1.Resource Allocation Graph with a deadlock
Safe State
A state is safe if the system can allocate resources to each process in some order
and still avoid a dead lock.
A deadlock is an unsafe state.
Not all unsafe states are dead locks
An unsafe state may lead to a dead lock
Claim edge - Claim edge Pi---> Rj indicates that process Pi may request resource Rj at
some time, represented by a dashed directed edge.
When process Pi request resource Rj, the claim edge Pi -> Rj is converted to a request
edge.
Safety algorithm
1. Initialize work := available and Finish [i]:=false for i=1,2,3 .. n
2. Find an i such that both
a. Finish[i]=false
b. Needi<= Work
if no such i exists, goto step 4
3. work :=work+ allocation i;
Finish[i]:=true
goto step 2
4. If finish[i]=true for all i, then the system is in a safe state
Resource Request Algorithm
Let Requesti be the request from process Pi for resources.
1. If Requesti<= Needi goto step2, otherwise raise an error condition, since the
process has exceeded its maximum claim.
2. If Requesti <= Available, goto step3, otherwise Pi must wait, since the resources are
not available.
3. Available := Availabe-Requesti;
Allocationi := Allocationi + Requesti
Needi := Needi - Requesti;
Now apply the safety algorithm to check whether this new state is safe or not.
If it is safe then the request from process Pi can be granted.
2.13.5 Deadlock Detection
(i) Single instance of each resource type
If all resources have only a single instance,
then we can define a deadlock detection algorithm
that use a variant of resource-allocation graph called a
wait for graph.
Resource Allocation Graph
Wait for S
Divide memory into fixed size partitions, where each partition has exactly
one process.
As processes complete and leave they create holes in the main memory.
Hole – block of available memory; holes of various size are scattered throughout
memory.
Solution:
First-fit: Allocate the first hole that is big enough.
Best-fit: Allocate the smallest hole that is big enough; must search entire list,
unless ordered by size. Produces the smallest leftover hole.
Worst-fit: Allocate the largest hole; must also search entire list. Produces the
largest leftover hole.
NOTE: First-fit and best-fit are better than worst-fit in terms of speed and storage utilization
Fragmentation
External Fragmentation – This takes place when enough total memory space
exists to satisfy a request, but it is not contiguous i.e, storage is fragmented into a
large number of small holes scattered throughout the main memory.
Example:
hole = 184 bytes
Process size = 182 bytes.
We are left with a hole of 2 bytes.
Solutions:
Coalescing : Merge the
adjacent holes together.
Compaction: Move all
processes towards one end of
memory, hole towards
other end of memory,
producing one large hole
of available memory.
This scheme is expensive
as it can be done if relocation
is dynamic and done at
execution time.
Permit the logical address
space of a process to be non-contiguous. This is achieved through two memory
management schemes namely paging and segmentation.
3.3 SEGMENTATION
Memory-management scheme that supports user view of memory
A program is a collection of segments.
A segment is a logical unit such as: Main program, Procedure, Function, Method, Object,
Local variables, global variables, Common block, Stack, Symbol table, arrays.
Segmentation Hardware
Logical address
consists of a two
tuple :
<Se
gm
ent-
nu
mb
er,
offs
et>
Segment table – maps two-dimensional physical addresses; each table entry has:
Base – contains the starting physical address where the segments
reside in memory
Limit – specifies the length of the segment
Segment-table base register (STBR) points to the segment table‘s location in memory
Segment-table length register (STLR) indicates number of segments used by a program;
Segment number=s‘ is legal, if s < STLR
Relocation.
dynamic
by segment table
Sharing.
shared segments
same segment number
Allocation.
first fit/best fit
external fragmentation
Protection: With each entry in segment table associate:
validation bit = 0 illegal segment
read/write/execute privileges
Protection bits associated with segments; code sharing occurs at segment level
Since segments vary in length, memory allocation is a dynamic storage-allocation
problem
A segmentation example is shown in the following diagram
Address
Translation
Scheme
Example
s g p
13 1 2
Where s designates the segment number, g indicates whether the segment is in the
GDT or LDT, and p deals with protection.
The offset is a 32-bit number specifying the location of the byte within the segment in
question.
The base and limit information about the segment in question are used to generate
a linear-address.
First, the limit is used to check for address validity. If the address is not valid, a memory
fault is generated, resulting in a trap to the operating system. If it is valid, then the value
of the offset is added to the value of the base, resulting in a 32-bit linear address. This
address is then translated into a physical address.
The linear address is divided into a page number consisting of 20 bits, and a page offset
consisting of 12 bits. Since we page the page table, the page number is further
divided into a 10-bit page directory pointer and a 10-bit page table pointer. The
logical address is as follows.
s g p
10 10 12
To improve the efficiency of physical memory use. Intel 386 page tables can be
swapped to disk. In this case, an invalid bit is used in the page directory entry to
indicate whether the table to which the entry is pointing is in memory or on disk.
If the table is on disk, the operating system can use the other 31 bits to specify the disk
location of the table; the table then can be brought into memory on demand.
3.3 PAGING
It is a memory management scheme that permits the physical address space of a process
to be noncontiguous.
It avoids the considerable problem of fitting the varying size memory chunks on to the
backing store.
(i) Basic Method:
Divide logical memory into blocks of same size called “pages”.
Divide physical memory into fixed-sized blocks called “frames”
Page size is a power of 2, between 512 bytes and 16MB.
Address Translation Scheme
Address generated by CPU(logical address) is divided into:
Page number (p) – used as an index into a page table which contains base address of
each page in physical memory
Page offset (d) – combined with base address to define the physical address i.e.,
Physical address = base address + offset
Allocation
When a process arrives into the system, its size (expressed in pages) is examined.
Each page of process needs one frame. Thus if the process requires =n‘ pages, at least =n‘
frames must be available in memory.
If =n‘ frames are available, they are allocated to this arriving process.
The 1st page of the process is loaded into one of the allocated frames & the frame
number is put into the page table.
Repeat the above step for the next pages & so on.
Frame table:
It is used to determine which frames are allocated, which frames are available, how
many total frames are there, and so on.(ie) It contains all the information about the frames
in the physical memory.
a)Before Allocation b) After Allocation
When a logical address is generated by CPU, its page number is presented to TLB.
TLB hit: If the page number is found, its frame number is immediately available & is
used to access memory
TLB miss: If the page number is not in the TLB, a memory reference to the page table
must be made.
Hit ratio: Percentage of times that a particular page is found in the TLB. For example
hit ratio is 80% means that the desired page number in the TLB is 80% of the time.
Effective Access Time:
Assume hit ratio is 80%. If it takes 20ns to search TLB & 100ns to access memory,
then the memory access takes 120ns(TLB hit)
If we fail to find page no. in TLB (20ns), then we must 1st access memory for page
table (100ns) & then access the desired byte in memory (100ns).
Therefore Total = 20 + 100 + 100
= 220 ns(TLB miss).
Then Effective Access Time (EAT) = 0.80 X (120 + 0.20) X 220.
= 140 ns.
Memory
protection
implemented by associating protection bit with each frame
“valid (v)” indicates that the associated page is in the process‘ logical address
space, and is thus a legal page
“invalid (i)” indicates that the page is not in the process‘ logical address space.
a) Hierarchical Paging
b) Hashed Page Tables
c) Inverted Page Tables
a) Hierarchical Paging
Break up the Page table into smaller pieces. Because if the page table is too large then it is quit
difficult to search the page number.
Example: “Two-Level Paging “
It requires more
number of memory accesses, when the number of levels is increased.
(b) Hashed Page Tables
Each entry in hash table contains a linked list of elements that hash to the same location.
Each entry consists of;
(a) Virtual page numbers
(b) Value of mapped page frame.
(c) Pointer to the next element in the linked list.
Working Procedure:
The virtual page number in the virtual address is hashed into the hash table.
Virtual page number is compared to field (a) in the 1st element in the linked list.
If there is a match, the corresponding page frame (field (b)) is used to form the desired
physical address.
If there is no match, subsequent entries in the linked list are searched for a matching
virtual page number.
Clustered page table:
It is a variation of hashed page table & is similar to hashed page table except that
each entry in the hash table refers to several pages rather than a single page.
Demerit: Improve the amount of time needed to search the table when a
page reference occurs.
(v) Shared Pages
One advantage of paging is the possibility of sharing common code.
Shared code
o One copy of read-only (reentrant) code shared among processes (i.e., text
editors, compilers, window systems).
o Shared code must appear in same location in the logical address space of
all processes
Reentrant code (Pure code): Non-self modifying code. If the code is reentrant, then
it never changes during execution. Thus two or more processes can execute the same
code at the same time.
Private code and data: Each process keeps a separate copy of the code and data.
Example:
Example:
Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1
No.of available frames = 3
No of Page Faults :12
LRU page replacement can be implemented using
1. Counters
Every page table entry has a time-of-use field and a clock or counter is associated
with the CPU.
Each time a page is referenced , copy the counter into the time-of-use field.
When a page needs to be replaced, replace the page with the smallest counter
value.
2. Stack
Whenever a page is referenced, remove the page from the stack and put it on top of the
stack.
When a page needs to be replaced, replace the page that is at the bottom of the
stack.(LRU page).
If reference bit is 00000000 then the page has not been used for 8 time periods.
If reference bit is 11111111 then the page has been used atleast once each time
period.
If the reference bit of page 1 is 11000100 and page 2 is 01110111 then page 2 is
the LRU page.
If 1 give the page a second chance and move on to the next FIFO page.
When a page gets a second chance, its reference bit is cleared and arrival time is
reset to current time.
Hence a second chance page will not be replaced until all other pages are replaced.
(iii) Enhanced Second Chance Algorithm
Consider both reference bit and modify bit
There are four possible classes
1. (0,0) – neither recently used nor modified Best page to replace
2. (0,1) – not recently used but modified page has to be written out before
replacement.
3. (1,0) - recently used but not modified page may be used again
4. (1,1) – recently used and modified page may be used again and page has to be
written to disk.
(e) Counting-Based Page Replacement
Keep a counter of the number of references that have been made to each page
Least Frequently Used (LFU )Algorithm: replaces page with smallest count
Most Frequently Used (MFU )Algorithm: replaces page with largest count
It is based on the argument that the page with the smallest count was probably just
brought in and has yet to be used.
3.7 THRASHING
High paging activity is called thrashing.
If a process does not have enough pages, the page-fault rate is very high.
This leads to:
o low CPU utilization
o operating system thinks that it needs to increase the degree of
multiprogramming
o another process is added to the system
When the CPU utilization is low, the OS increases the degree of
multiprogramming.
If global replacement is used then as processes enter the main memory they tend to steal
frames belonging to other processes.
Eventually all processes will not have enough frames and hence the page fault rate
becomes very high.
Thus swapping in and swapping out of pages only takes place. This is the cause of
thrashing.
To limit thrashing, we can use a local replacement algorithm.
To prevent thrashing, there are two methods namely ,
D = WSSi
W
h
e
r
e
W
SSi is the working set size for process i.
D is the total demand of frames
if D > m then Thrashing will occur.
2. Page-Fault Frequency Scheme
Other Issues
Prepaging
To reduce the large number of page faults that occurs at process startup
Prepage all or some of the pages a process will need, before they are referenced
But if prepaged pages are unused, I/O and memory are wasted
Page Size
Page size selection must take into consideration:
fragmentation
table size
I/O overhead
locality
TLB Reach
Increase the Page Size. This may lead to an increase in fragmentation as not all
applications require a large page size
Provide Multiple Page Sizes. This allows applications that require larger
page sizes the opportunity to use them without an increase in fragmentation.
I/O interlock
Pages must sometimes be locked into memory
Consider I/O. Pages that are used for copying a file from a device must be locked
from being selected for eviction by a page replacement algorithm.
Overview
One of the responsibilities of the operating system is to use the hardware efficiently.
For the disk drives,
o A fast access time and
o High disk bandwidth.
The access time has two major components;
The seek time is the time for the disk arm to move the heads to the cylinder containing
the desired sector.
The rotational latency is the additional time waiting for the disk to rotate the desired
sector to the disk head.
The disk bandwidth is the total number of bytes transferred, divided by the total time
between the first request for service and the completion of the last transfer.
We can improve both the access time and the bandwidth by disk scheduling.
Servicing of disk I/O requests in a good order.
4.2 DISK SCHEDULING AND MANAGEMENT
4.2.1 Disk scheduling
4.2.1.1 FCFS Scheduling
4.2.1.2 SSTF (shortest-seek-time-first)Scheduling
Service all the requests close to the current head position, before moving the head far away to
service other requests. That is selects the request with the minimum seek time from the current
head position.
Boot Block:
For a computer to start running-for instance, when it is powered up or rebooted-it needs
to have an initial program to run. This initial progr am is called bootstrap program & it
should be simple. It initializes all aspects of the system, from CPU registers to device
controllers and the contents of main memory, and then starts the operating system.
To do its job, the bootstrap program
1. Finds the operating system kernel on disk,
2. Loads that kernel into memory, and
3. Jumps to an initial address to begin the operating-system execution.
Advantages:
1. ROM needs no initialization.
2. It is at a fixed location that the processor can start executing when powered up or
reset.
3. It cannot be infected by a computer virus. Since, ROM is read only.
The full bootstrap program is stored in a partition called the boot blocks, at a fixed
location on the disk. A disk that has a boot partition is called a boot disk or system disk.
The code in the boot ROM instructs the disk controller to read the boot blocks into
memory and then starts executing that code.
Bootstrap loader: load the entire operating system from a non-fixed location on disk, and
to start the operating system running.
Bad Blocks:
The disk with defected sector is called as bad block.
Depending on the disk and controller in use, these blocks are handled in a variety of
ways;
Method 1: “Handled manually
If blocks go bad during normal operation, a special program must be run manually
to search for the bad blocks and to lock them away as before. Data that resided on
the bad blocks usually are lost.
Method 2: “sector sparing or forwarding”
The controller maintains a list of bad blocks on the disk. Then the controller can
be told to replace each bad sector logically with one of the spare sectors. This
scheme is known as sector sparing or forwarding.
A typical bad-sector transaction might be as follows:
1. The oper ating system tries to read logical block 87.
2. The controller calculates the ECC and finds that the sector is bad.
3. It reports this finding to the operating system.
4. The next time that the system is rebooted, a special command is run to tell the
controller to replace the bad sector with a spare.
5. After that, whenever the system requests logical block 87, the request is translated into
the
replacement sector's address by the controller.
Name: The symbolic file name is the only information kept in human
readable form.
Identifier: This unique tag, usually a number identifies the file within the file
system. It is the non-human readable name for the file.
Type: This information is needed for those systems that support different types.
Location: This information is a pointer to a device and to the location of the file
on that device.
Size: The current size of the file (in bytes, words or blocks)and possibly the
maximum allowed size are included in this attribute.
Time, date and user identification: This information may be kept for
creation, last modification and last use. These data can be useful for
protection, security and usage monitoring.
4.3.3 File Operations
Creating a file
Writing a file
Reading a file
Repositioning within a file
Deleting a file
Truncating a file
4.3.4 File Types
Library lib, a, so, dll, mpeg, mov, Libraries of routines for programmers
rm
Archive arc, zip, tar Related files grouped into one file,
sometimes compressed, for archiving or
storage
Remote file systems allow a computer to a mount one or more file systems from one or
more remote machines.
A server can serve multiple clients, and a client can use multiple servers,
depending on the implementation details of a given client –server facility.
Distributed information systems, also known as distributed naming service, have been
devised to provide a unified access to the information needed for remote computing.
c) Failure Modes:
Redundant arrays of inexpensive disks (RAID) can prevent the loss of a disk from
resulting in the loss of data.
Remote file system has more failure modes. By nature of the complexity of networking system
and the required interactions between remote machines, many more problems can interfere with
the proper operation of remote file systems.
d) Consistency Semantics:
It is characterization of the system that specifies the semantics of multiple users accessing
a shared file simultaneously.
These semantics should specify when modifications of data by one user are observable by
other users.
The semantics are typically implemented as code with the file system.
A series of file accesses (that is reads and writes) attempted by a user to the same file is
always enclosed between the open and close operations.
The series of access between the open and close operations is a file session.
(i) UNIX Semantics:
The UNIX file system uses the following consistency semantics:
1. Writes to an open file by a user are visible immediately to other users that have this
file open at the same time.
2. One mode of sharing allows users to share the pointer of current location into
the file. Thus, the advancing of the pointer by one user affects all sharing users.
(ii) Session Semantics:
The Andrew file system (AFS) uses the following consistency semantics:
1. Writes to an open file by a user are not visible immediately to other users that have
the same file open simultaneously.
2. Once a file is closed, the changes made to it are visible only in sessions
starting later. Already open instances of the file do not reflect this change.
(iii) Immutable –shared File Semantics:
Once a file is declared as shared by its creator, it cannot be modified.
An immutable file has two key properties:
Its name may not be reused and its contents may not be altered.
4.6 FILE PROTECTION
4.6.1 Need for file protection.
Protection can be provided in many ways. For a small single-user system, we might
provide protection by physically removing the floppy disks and locking them in a
desk drawer or file cabinet. In a multi-user system, however, other mechanisms are
needed.
4.6.2 Types of Access
Protection mechanisms provide controlled access by limiting the types of file access
that can be made. Access is permitted or denied depending on several factors, one of
which is the type of access requested. Several different types of operations may be
controlled:
1. Read: Read from the file.
2. Write: Write or rewrite the file.
3. Execute: Load the file into memory and execute it.
4. Append: Write new information at the end of the file.
5. Delete: Delete the file and free its space for possible reuse.
6. List: List the name and attributes of the file.
4.6.3 Access Control
Associate with each file and directory an access-control list (ACL) specifying the
user name and the types of access allowed for each user.
When a user requests access to a particular file, the operating system checks the access
list associated with that file. If that user is listed for the requestedaccess, the access is
allowed. Otherwise, a protection violation occurs and the user job is denied access to the
file.
The directory entry, previously of fixed size, now needs to be of variable size,
resulting in more complicated space management.
To condense the length of the access control list, many systems recognize three
classifications of users in connection with each file:
Owner: The user who created the file is the owner.
Group: A set of users who are sharing the file and need similar access \is a group, or
work group.
Universe: All other users in the system constitute the universe.
The bulk of the operations on a file is reads and writes. A read operation reads the next
portion of the file and automatically advances a file pointer, which tracks the I/O
location. Similarly, a write appends to the end of the file and advances to the end
of the newly written material (the new end of file). Such a file can be reset to the
beginning and, on some systems, a program may be able to skip forward or back ward
n records, for some integer n-perhaps only for n=1. Sequential access is based on
a tape model of a file, and works as well on sequential-access devices as it does on
random – access ones.
2. Direct Access
Another method is direct access (or relative access). A file is made up of fixed length
logical records that allow programs to read and write records rapidly in no particular
order. The direct- access methods is based on a disk model of a file, since disks allow
random access to any file block.
For direct access, the file is viewed as a numbered sequence of blocks or records. A
direct-access file allows arbitrary blocks to be read or written. Thus, we may read block
14, then read block 53, and then write block7. There are no restrictions on the
order of reading or writing for a direct-access file.
Direct – access files are of great use for immediate access to large amounts of
information. Database is often of this type. When a query concerning a particular
subject arrives, we compute which block contains the answer, and then read that block
directly to provide the desired information.
As a simple example, on an air line – reservation system, we might store all the
information about a particular flight (for example, flight 713) in the block
identified by the flight number.
Thus, the number of available seats for flight 713 is stored in block 713 of the
reservation file. To store information about a larger set, such as people, we might
compute a hash function on the people’s names, or search a small in- memory
index to determine a block to read and search.
With large files, the index file itself may become too large to be kept in
memory. One solution is to create an index for the index file. The primary index file
would contain pointers to secondary index tiles, which would point to the
actual data items.
4.9 DIRECTORY STRUCTURE
There are five directory structures. They are
1. Single-level directory
2. Two-level directory
3. Tree-Structured directory
4. Acyclic Graph directory
5. General Graph directory
Directory
Disadvantages:
1. Finding space for a new
file.
Disadvantages:
1. Used effectively
only for sequential access files.
To find the ith block of a file, we must start at the beginning of that file, and follow the
pointers until we get to the ith block. Each aces to a pointer requires a disk read,
and sometimes a disk seek consequently, it is inefficient to support a direct- access
capability for linked allocation files.
2. Space required for the pointers
If a pointer requires 4 bytes out of a 512-byte block, then 0.78 percent of the disk is being
used for pointers, rather than for information.
Solution to this problem is to collect blocks into multiples, called clusters, and to allocate
the clusters rather than blocks. For instance, the file system may define a clusters as 4
blocks, and operate on the disk in only cluster units.
3. Reliability
Since the files are linked together by pointers scattered all over the disk hardware
failure might result in picking up the wrong pointer. This error could result in
linking into the free- space list or into another file. Partial solution are to use doubly
linked lists or to store the file names in a relative block number in each block; however,
these schemes require even more over head for each file.
Linked allocation solves the external – fragmentation and size- declaration problems of
contiguous allocation.
Linked allocation cannot support efficient direct access, since the pointers to the blocks
are scattered with the blocks themselves all over the disk and need to be retrieved in
order.
Indexed allocation solves this problem by bringing all the pointers together into one
location: the index block.
Each file has its own index block, which is an array of disk – block addresses.
The ith entry in the index block points to the ith block of the file.
The directory contains the address of the index block .
To read the ith block, we use the pointer in the ith index – block entry to find and read the
desired block this scheme is similar to the paging scheme .
When the file is created, all pointers in the pointers in the index block are set to nil. when
the ith block is first written, a block is obtained from the free space manager, and its
address is put
in the ith
index – block
entry.
Indexed
allocation
supports
direct access,
without
suffering
from external
fragmentation
, because any
free block on
the disk may
satisfy a
request for
more space.
Disadvantages
1.Pointer Overhead
Indexed allocation does suffer from wasted space. The pointer over head of the index block
is generally greater than the pointer over head of linked allocation.
3. Grouping
A modification of the free-list approach is to store the addresses of n free blocks in the
first free block.
The first n-1 of these blocks are actually free.
The last block contains the addresses of another n free blocks, and so on.
The importance of this implementation is that the addresses of a large number of
free blocks can be found quickly.
4. Counting
We can keep the address of the first free block and the number n of free
contiguous blocks that follow the first block.
Each entry
in the free-
space list
then consists
of a disk
address and
a count.
Although
each entry
requires
more space
than would a
simple disk
address, the
overall list will be shorter, as long as the count is generally greater than 1.
Recovery
Files and directories are kept both in main memory and on disk, and care must be taken to
ensure that system failure does not result in loss of data or in data inconsistency.
1. Consistency Checking
The directory information in main memory is generally more up to date than is the
corresponding information on the disk, because cached directory information is not
necessarily written to disk as soon as the update takes place.
Frequently, a special program is run at reboot time to check for and correct disk
inconsistencies.
Magnetic disks sometimes fail, and care must be taken to ensure that the data lost in
such a failure are not lost forever. To this end, system programs can be used to back up
data from disk to another storage device, such as a floppy disk, magnetic tape, optical
disk, or other hard disk.
Recovery from the loss of an individual file, or of an entire disk, may then be a matter of
restoring the data from backup.
1. Module Management
Loading a module requires more than just loading its binary contents into kernel memory.
The system must also make sure that any references the correct locations in the kernel’s
address space. Linux deals with this reference updating by splitting the job of module
loading into two separate sections: the management of sections of module code in kernel
memory and the handling of symbols that modules are allowed to reference.
Linux maintains an internal symbol table in the kernel. This symbol table does not
contain the full set of symbols defined in the kernel during the latter’s compilation;
rather, a symbol must be explicitly exported. The set of exported symbols constitutes a
well-defined interface by which a module can interact with the kernel.
2. Driver Registration
Once a module is loaded, it remains no more than an isolated region of memory until it
lets the rest of the kernel know what new functionality it provides. The kernel maintains
dynamic tables of all known drivers and provides a set of routines to allow drivers to be
added to or removed from these tables at any time. The kernel makes sure that it calls a
module’s startup routine when that module is loaded and calls the module’s cleanup
routine before that module is unloaded. These routines are responsible for registering the
module’s functionality.
A module may register many types of functionality; it is not limited to only one type. For
example, a device driver might want to register two separate mechanisms for accessing
the device. Registration tables include, among others, the following items:
• Device drivers. These drivers include character devices (such as printers,
terminals, and mice), block devices (including all disk drives), and network
interface devices.
• File systems. The file system may be anything that implements Linux’s virtual
file system calling routines. It might implement a format for storing files on a
disk, but it might equally well be a network file system, such as NFS, or a virtual
file system whose contents are generated on demand, such as Linux’s /proc file
system.
• Network protocols. A module may implement an entire networking protocol,
such as TCP or simply a new set of packet-filtering rules for a network firewall.
• Binary format. This format specifies a way of recognizing, loading, and
executing a new type of executable file.
3. Conflict Resolution
Commercial UNIX implementations are usually sold to run on a vendor’s own hardware.
One advantage of a single-supplier solution is that the software vendor has a good idea
about what hardware configurations are possible. PC hardware, however, comes in a vast
number of configurations, with large numbers of possible drivers for devices such as
network cards and video display adapters. The problem of managing the hardware
configuration becomes more severe when modular device drivers are supported, since the
currently active set of devices becomes dynamically variable.
Linux provides a central conflict-resolution mechanism to help arbitrate access to certain
hardware resources. Its aims are as follows:
• To prevent modules from clashing over access to hardware resources
• To prevent autoprobes—device-driver probes that auto-detect device configuration—
from interfering with existing device drivers
• To resolve conflicts among multiple drivers trying to access the same hardware—as, for
example, when both the parallel printer driver and the parallel line IP (PLIP) network
driver try to talk to the parallel port.
5.3.2 Kernel
The kernel layer ofWindows has four main responsibilities: thread scheduling, low-level
processor synchronization, interrupt and exception handling, and switching between user
mode and kernel mode. The kernel is implemented in the C language, using assembly
language only where absolutely necessary to interface with the lowest level of the
hardware architecture.
5.3.3 Kernel Dispatcher
The kernel dispatcher provides the foundation for the executive and the subsystems. Most
of the dispatcher is never paged out of memory, and its execution is never preempted. Its
main responsibilities are thread scheduling and context switching, implementation of
synchronization primitives, timer management, software interrupts (asynchronous and
deferred procedure calls), and exception dispatching.
5.3.4 Threads and Scheduling
Like many other modern operating systems, Windows uses processes and threads for
executable code. Each process has one or more threads, and each thread has its own
scheduling state, including actual priority, processor affinity, and CPU usage information.
There are six possible thread states: ready, standby, running, waiting, transition, and
terminated. Ready indicates that the thread is waiting to run. The highest-priority ready
thread is moved to the standby state, which means it is the next thread to run. In a
multiprocessor system, each processor keeps one thread in a standby state. A thread is
running when it is executing on a processor. It runs until it is preempted by a higher-
priority thread, until it terminates, until its allotted execution time (quantum) ends, or
until it waits on a dispatcher object, such as an event signaling I/O completion. A thread
is in the waiting state when it is waiting for a dispatcher object to be signaled. A thread is
in the transition state while it waits for resources necessary for execution; for example, it
may be waiting for its kernel stack to be swapped in from disk. A thread enters the
terminated state when it finishes execution.
5.3.5 Implementation of Synchronization Primitives
Key operating-system data structures are managed as objects using common facilities for
allocation, reference counting, and security. Dispatcher objects control dispatching and
synchronization in the system. Examples of these objects include the following:
• The event object is used to record an event occurrence and to synchronize this
occurrence with some action. Notification events signal all waiting threads, and
synchronization events signal a single waiting thread.
• The mutant provides kernel-mode or user-mode mutual exclusion associated with the
notion of ownership.
• The mutex, available only in kernel mode, provides deadlock-free mutual exclusion.
• The semaphore object acts as a counter or gate to control the number of threads that
access a resource.
• The thread object is the entity that is scheduled by the kernel dispatcher. It is associated
with a process object, which encapsulates a virtual address space. The thread object is
signaled when the thread exits, and the process object, when the process exits.
• The timer object is used to keep track of time and to signal timeouts when operations
take too long and need to be interrupted or when a periodic activity needs to be
scheduled.
Power ON Self-Test
When the DPR-1020 is powered ON, it automatically performs a Self-Test on each of its
major components. The final result of the Self-Test is signaled by the state of the USB
LED indicator following the Self-Test. Preliminary to the actual component tests, the
three LED indicators are tested to confirm their operation.
Immediately after power-up, all three of the blue LEDs should illuminate steadily for
several seconds. Then the USB LED should light OFF simultaneously. Irregularity of any
of the three LEDs during these LED tests may mean there is a problem with the LEDs
themselves.
The actual component tests immediately follow the LED tests. A normal (no fault) result
is signaled by simultaneous flashing of the LEDs three times, followed by a quiescent
state with all three LEDs dark.
If the Self-Test routine traps any component error, then following the LED tests the Self-
Test will halt and the LEDs will continuously signal the error according to the following
table. In the event of any such error signal, contact your dealer for correction of the faulty
unit.
Getting Started
Below is a sample network using the DPR-1020. The DPR-1020 has a built- in web
configurator that allows users to easily configure the Print Server and manage multiple
print queues through TCP/IP.
Auto-Run Installation
Insert the included installation CD into your computer’s CD-ROM drive to initiate the
auto-run program. If auto-run does not start, click My Computer > [CD ROM Drive Letter].
The content of the installation CD-ROM includes:
• Install PS Software – click this to install the PS Software, which contains PS-Link and
PS-Wizard that can configure more settings for the MFP Server, such as:
- Change the IP address
- Support the multi-functions (Print/Scan/Copy/Fax) of a MFP printer, GDI
printing, and other software from any MFP/GDI printer.
`- Easily add a printer to your computer.
• View Quick Installation Guide – click this to preview the Quick Installation Guide in
PDF format for step-by-step instructions of the MFP Server Installation.
• View Manual – click this to preview the User Manual in PDF format for detailed
information regarding the MFP Server.
• Install Acrobat Reader – click this to install Acrobat Reader for the viewing and
printing of PDF files found in this Installation CD-ROM.
• Exit – click to close the Auto-Run program.
5.5 DOMAIN NAME SYSTEM
The domain name, or network name, is a unique name followed by a standard Internet suffixes
such as .com, .org, .mil, .net, etc. You can pretty much name your LAN anything if it has a
simple dial-up connection and your LAN is not a server providing some type of service to other
hosts directly. In addition, our sample network is considered private since it uses IP addresses in
the range of 192.168.1.x. Most importantly, the domain name of choice should not be accessible
from the Internet if the above constraints are strictly enforced. Lastly, to obtain an "official"
domain name you could register through InterNIC, Network Solutions or Register.com. See the
Resources section later in this article for the Web sites with detailed instructions for obtaining
official domain names.
Hostnames
Another important step in setting up a LAN is assigning a unique hostname to each
computer in the LAN. A hostname is simply a unique name that can be made up and is
used to identify a unique computer in the LAN. Also, the name should not contain any
blank spaces or punctuation. For example, the following are valid hostnames that could
be assigned to each computer in a LAN consisting of 5 hosts: hostname 1 - Morpheus;
hostname 2 - Trinity; hostname 3 - Tank; hostname 4 - Oracle; and hostname 5 - Dozer.
Each of these hostnames conforms to the requirement that no blank spaces or punctuation
marks are present. Use short hostnames to eliminate excessive typing, and choose a name
that is easy to remember.
Every host in the LAN will have the same network address, broadcast address, subnet
mask, and domain name because those addresses identify the network in its entirety. Each
computer in the LAN will have a hostname and IP address that uniquely identifies that
particular host. The network address is 192.168.1.0, and the broadcast address is
192.168.1.128. Therefore, each host in the LAN must have an IP address between
192.168.1.1 to 192.168.127.
Introduction to TCP/IP
TCP/IP is the suite of protocols used by the Internet and most LANs throughout the
world. In TCP/IP, every host (computer or other communications device) that is
connected to the network has a unique IP address. An IP address is composed of four
octets (numbers in the range of 0 to 255) separated by decimal points. The IP address is
used to uniquely identify a host or computer on the LAN. For example, a computer with
the hostname Morpheus could have an IP address of 192.168.7.127. You should avoid
giving two or more computers the same IP address by using the range of IP addresses that
are reserved for private, local area networks; this range of IP addresses usually begins
with the octets 192.168.
LAN network address The first three octets of an IP address should be the same for all
computers in the LAN. For example, if a total of 128 hosts exist in a single LAN, the IP
addresses could be assigned starting with 192.168.1.x, where x represents a number in the
range of 1 to 128. You could create consecutive LANs within the same company in a
similar manner consisting of up to another 128 computers. Of course, you are not limited
to 128 computers, as there are other ranges of IP addresses that allow you to build even
larger networks.
There are different classes of networks that determine the size and total possible unique
IP addresses of any given LAN. For example, a class A LAN can have over 16 million
unique IP addresses. A class B LAN can have over 65,000 unique IP addresses. The size
of your LAN depends on which reserved address range you use and the subnet mask
(explained later in the article) associated with that range (see Table 1.).
Another important aspect of building a LAN is that the addresses at the two extreme ends
of the address range are reserved for use as the LAN's network address and broadcast
address. The network address is used by an application to represent the overall network.
The broadcast address is used by an application to send the same message to all other
hosts in the network simultaneously.
For example, if you use addresses in the range of 192.168.1.0 to 192.168.1.128, the first
address (192.168.1.0) is reserved as the network address, and the last address
(192.168.1.128) is reserved as the broadcast address. Therefore, you only assign
individual computers on the LAN IP addresses in the range of 192.168.1.1 to
192.168.1.127:
Subnet masks
Each host in a LAN has a subnet mask. The subnet mask is an octet that uses the number
255 to represent the network address portion of the IP address and a zero to identify the
host portion of the address. For example, the subnet mask 255.255.255.0 is used by each
host to determine which LAN or class it belongs to. The zero at the end of the subnet
mask represents a unique host within that network.
There are two ways to assign IP addresses in a LAN. You can manually assign a static IP
address to each computer in the LAN, or you can use a special type of server that
automatically assigns a dynamic IP address to each computer as it logs into the network.
Static IP addressing
Dynamic IP addressing
You can set preferences, such as how devices are displayed in VMware Player.
You can change the amount of memory allocated to the virtual machine.
You can drag and drop files between a Linux or Windows host and a Linux,
Windows, or Solaris guest.(Linux hosts and Linux and Solaris guests must be
running X Windows.) You can use this feature if theperson who created the
virtual machine you are running also installed VMware Tools in it.
You can copy and paste text between a Windows or Linux host and a Windows,
Linux, or Solaris guest.
You can use this feature if the person who created the virtual machine you are
running also installed VMware Tools in it.
You can copy and paste files between a Windows or Linux host and a Windows,
Linux, or Solaris guest.
You can use this feature if the person who created the virtual machine you are
running also installed VMware Tools in it.
Part- A
2. Why is the Operating System viewed as a resource allocator & control program?
A computer system has many resources – hardware & software that may be required to
solve a problem, like CPU time, memory space, file-storage space, I/O devices & so on. The OS
acts as a manager for these resources so it is viewed as a resource allocator. The OS is viewed
as a control program because it manages the execution of user programs to prevent errors &
improper use of the computer.
A more common definition is that the OS is the one program running at all times on the
computer, usually called the kernel, with all else being application programs.
Batch systems are quite appropriate for executing large jobs that need little
interaction. The user can submit jobs and return later for the results. It is not necessary to wait
while the job is processed. Operators batched together jobs with similar needs and ran them
through the computer as a group.
Interactive computer system provides direct communication between the user and the system.
The user gives instructions to the operating system or to a program directly, using a keyboard or
mouse, and waits for immediate results.
Multiprocessor systems also known as parallel systems or tightly coupled systems are
systems that have more than one processor in close communication, sharing the computer bus,
the clock and sometimes memory & peripheral devices. Their main advantages are,
Increased throughput
Economy of scale
Increased reliability
Symmetric multiprocessing (SMP): In SMP each processor runs an identical copy of the OS
& these copies communicate with one another as needed. All processors are peers.
Examples are Windows NT, Solaris, Digital UNIX, and OS/2 & Linux.
In multiprocessor systems, failure of one processor will not halt the system, but only slow
it down. If there is ten processors & if any one fails then the remaining nine processors pick
up the work of the failed processor. This ability to continue providing service is proportional to
the surviving hardware is called graceful degradation.
The dual mode operation provides us with the means for protecting the operating
system from wrong users and wrong users from one another. User mode and monitor mode are
the two modes. Monitor mode is also called supervisor mode, system mode or privileged mode.
Mode bit is attached to the hardware of the computer in order to indicate the current mode. Mode
bit is ‘0’ for monitor mode and ‘1’ for user mode.
Some of the machine instructions that may cause harm to a system are designated as
privileged instructions. The hardware allows the privileged instructions to be executed only in
monitor mode.
13. How can a user program disrupt the normal operations of a system?
The protection against illegal memory access is done by using two registers. The base
register and the limit register. The base register holds the smallest legal physical address; the
limit register contains the size of the range. The base and limit registers can be loaded only by
the OS using special privileged instructions
-memory management
I/O-system management
-storage management
-interpreter system
17. What is a Process State and mention the various States of a Process?
As a process executes, it changes state. The state of a process is defined in part by the
current activity of that process.
ed
19. What is the use of Job Queues, Ready Queues & Device Queues?
As a process enters a system, they are put into a job queue. This queue consists of all jobs
in the system. The processes that are residing in main memory and are ready & waiting to
execute are kept on a list called ready queue. The list of processes waiting for a particular I/O
device is kept in the device queue.
Switching the CPU to another process requires saving the state of the old process and
loading the saved state for the new process. This task is known as context switch. The context of
a process is represented in the PCB of a process.
System calls provide the interface between a process and the Operating system.
System Calls are also called as Monitor call or Operating-system function call. When a
system call is executed, it is treated as by the hardware as software interrupt. Control passes
through the interrupt vector to a service routine in the operating system, and the mode bit is set to
monitor mode.
-System manipulation
ection
A hard real time system guarantees that critical tasks complete on time. In a soft real time
system, a critical real-time task gets priority over the other tasks, and retains that priority until it
completes. Soft real time systems have more limited utility than do hard real-time systems.
The operating system picks and begins to execute one of the jobs in the memory.
Eventually, the job may have to wait for some task, such as a tape to be mounted, or an I/O
operation to complete. In a non-multiprogrammed system, the CPU would sit idle. In a
multiprogramming system, the operating system simply switches to and executes another job.
When that job needs to wait, the CPU is switched to another job, and so on. Eventually, the first
job finishes waiting and gets the CPU back. As long as there is always some job to
execute, the CPU will never be idle.
The requirements can be divided into two basic groups: User goals and System
goals.Users desire that the system should be convenient and easy to use, easy to learn, reliable,
safe and fast. The Operating system should be easy to design, implement, and maintain. Also it
should be flexible, reliable, error free and efficient. These are some of the requirements,
which are vague and have no general solution.
-management
Device-management
Fork is a System calls by which a new process is created. Execve is also a System call,
which is used after a fork by one of the two processes to replace the process memory space
with a new program.
Maximum CPU Time: Maximum amount of CPU time a process may use.
2. Explain how protection is provided for the hardware resources by the operating system.
3. What are the system components of an operating system and explain them?
4. What are the various process scheduling concepts?
6. List five services provided by an operating system. Explain how each provides convenience to
the users. Explain also in which cases it would be impossible for user level programs to
provide these services.
UNIT – II
Part – A
1. What is a Thread?
A thread otherwise called a lightweight process (LWP) is a basic unit of CPU utilization, it comprises
of a thread id, a program counter, a register set and a stack. It shares with other threads belonging to the
same process its code section, data section, and operating system resources such as open files and
signals.
The benefits of multithreaded programming can be broken down into four major categories:
Responsiveness
Resource sharing
Economy
The thread cancellation is the task of terminating a thread before it has completed.
A thread that is to be cancelled is often referred to as the target thread. For example, if multiple
threads are concurrently searching through a database and one thread returns the result, the
remaining threads might be cancelled.
CPU scheduling is the process of switching the CPU among various processes. CPU
scheduling is the basis of multiprogrammed operating systems. By switching the CPU among
processes, the operating system can make the computer more productive.
Under non - preemptive scheduling once the CPU has been allocated to a process, the process
keeps the CPU until it releases the CPU either by terminating or switching to the
waiting state.
Preemptive scheduling can preempt a process which is utilizing the CPU in between its
execution and give the CPU to another process.
7. What is a Dispatcher?
The dispatcher is the module that gives control of the CPU to the process selected by the
short-term scheduler. This function involves:
ng context
ng to user mode
to the proper location into the user program to restart that program.
The time taken by the dispatcher to stop one process and start another running is known as
dispatch latency.
Throughput in CPU scheduling is the number of processes that are completed per unit time.
For long processes, this rate may be one process per hour; for short transactions,
throughput might be 10 processes per second.
Turnaround time is the interval from the time of submission to the time of completion of
a process. It is the sum of the periods spent waiting to get into memory, waiting in the ready
queue, executing on the CPU, and doing I/O.
When several process access and manipulate same data concurrently, then the
outcome of the execution depends on particular order in which the access takes place is called
race condition. To avoid race condition, only one process at a time can manipulate the shared
variable.
Consider a system consists of ‘n‘processes. Each process has segment of code called a
critical section, in which the process may be changing common variables, updating a table,
writing a file. When one process is executing in its critical section, no other process can
allowed executing in its critical section.
14. What are the requirements that a solution to the Critical Section Problem must satisfy?
d waiting
The critical section problem is to design a protocol that the processes can use to
cooperate. Each process must request permission to enter its critical section. The section of the
code implementing this request is the entry section. The critical section is followed by an exit
section. The remaining code is the remainder section.
16. Give two hardware instructions and their definitions which can be used for
implementing Mutual Exclusion.
Test And Set
boolean TestAndSet (boolean &target)
{
boolean rv = target;
target = true;
return rv;
}
Swap
void Swap (boolean &a, boolean &b)
{
boolean temp = a;
a = b;
b = temp;
Semaphores can be used to deal with the n-process critical section problem. It can be also used to
solve various synchronization problems.
The classic definition of ‘wait’
wait (S)
{
while (S<=0)
S--;
}
The classic definition of ‘signal’
signal (S)
{
S++;
}
When a process is in its critical section, any other process that tries to enter its critical
section must loop continuously in the entry code. This is called as busy waiting and this type of
semaphore is also called a spinlock, because the process while waiting for the lock.
20. How can we say the First Come First Served scheduling algorithm is Non Preemptive?
Once the CPU has been allocated to the process, that process keeps the CPU until it
releases, either by terminating or by requesting I/O. So we can say the First Come First
Served scheduling algorithm is non preemptive.
Waiting time is the sum of periods spent waiting in the ready queue. CPU scheduling
algorithm affects only the amount of time that a process spends waiting in the ready queue.
Response time is the measure of the time from the submission of a request until the first
response is produced. Response time is amount of time it takes to start responding, but not the
time that it takes to output that response.
The long-term scheduler or job scheduler selects processes from the job pool and loads them into
memory for execution.
The short-term scheduler or CPU scheduler selects from among the process that are ready to
execute, and allocates the CPU to one of them.
-Buffer Problem
-Writers Problem
25. When the error will occur when we use the Semaphore?
A way of making sure that if one process is using a shared modifiable data, the
other processes will be excluded from doing the same thing. Each process executing the shared
data variables excludes all others from doing so simultaneously. This is called mutual exclusion.
Critical regions are small and infrequent so that system through put is largely unaffected
by their existence. Critical region is a control structure for implementing mutual exclusion over
a shared variable.
A two dimensional chart that plots the activity of a unit on the Y-axis and the time on the
X-axis. The chart quickly represents how the activities of the units are serialized.
A process requests resources; if the resources are not available at that time, the process
enters a wait state. Waiting processes may never again change state, because the resources they
have requested are held by other waiting processes. This situation is called a deadlock.
33. What are conditions under which a deadlock situation may arise?
A deadlock situation can arise if the following four conditions hold simultaneously in a
system:
-emption
rcular wait
Deadlocks can be described more precisely in terms of a directed graph called a system
resource allocation graph. This graph consists of a set of vertices V and a set of edges E. The set
of vertices V is partitioned into two different types of nodes; P the set consisting of all active
processes in the system and R the set consisting of all resource types in the system.
A directed edge from process Pi to resource type Rj is denoted by Pi Rj; it signifies that
process Pi requested an instance of resource type Rj and is currently waiting for that resource. A
directed edge from resource type Rj to process Pi is denoted by RjàPi, it signifies that an instance
of resource type has been allocated to a process Pi. A directed edge PiàRj is called a request
edge. A directed edge RjàPi is called an assignment edge.
The deadlock problem can be dealt with in one of the three ways:
he problem all together, and pretend that deadlocks never occur in the system.
Deadlock prevention is a set of methods for ensure that at least any one of the four
necessary conditions like mutual exclusion, hold and wait, no pre-emption and circular wait
cannot hold. By ensuring that that at least one of these conditions cannot hold, the occurrence of
a deadlock can be prevented.
A state is safe if the system can allocate resources to each process in some order and still
avoid a deadlock. A system is in 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 that Pi can still request can be satisfied by the current available resource plus the
resource held by all the Pj, with j<i. if no such sequence exists, then the system state is said to be unsafe.
Safety algorithm: The algorithm for finding out whether or not a system is in a safe
state.
address generated by the CPU is referred as logical address. An address seen by the
memory unit that is the one loaded into the memory address register of the memory is
commonly referred to as physical address.
42. What are Logical Address Space and Physical Address Space?
The set of all logical addresses generated by a program is called a logical address space;
the set of all physical addresses corresponding to these logical addresses is a physical address
space.
44. What are the methods for dealing the Deadlock Problem?
otocol to ensure that the system will never enter a deadlock state.
he problem all together, and pretend that deadlocks never occur in the system.
45. Differentiate Deadlock and Starvation.
A set of processes is in deadlock state when every process in the set is waiting
for an event that can be caused only by the other process in the set. Starvation or indefinite
blocking is a situation where processes wait indefinitely within the semaphore.
PART - B
Dynamic linking is similar to dynamic loading, rather that loading being postponed until
execution time, linking is postponed. This feature is usually used with system libraries, such as
language subroutine libraries. A stub is included in the image for each library-routine reference.
The stub is a small piece of code that indicates how to locate the appropriate memory-resident
library routine, or how to load the library if the routine is not already present.
To enable a process to be larger than the amount of memory allocated to it, overlays
are used. The idea of overlays is to keep in memory only those instructions and data that are
needed at a given time. When other instructions are needed, they are loaded into space occupied
previously by instructions that are no longer needed.
4. Define Swapping.
Best fit allocates the smallest hole that is big enough. The entire list has to be
searched, unless it is sorted by size. This strategy produces the smallest leftover hole.
First fit allocates the first hole that is big enough. Searching can either start at the
beginning of the set of holes or where the previous first-fit search ended. Searching can be
stopped as soon as a free hole that is big enough is found.
Protection bits that are associated with each frame accomplish memory protection in a
paged environment. The protection bits can be checked to verify that no writes are being made to
a read-only page.
When the allocated memory may be slightly larger than the requested memory, the
difference between these two numbers is internal fragmentation.
Compaction is a solution to external fragmentation. The memory contents are shuffled to place
all free memory together in one large block. It is possible only if relocation is dynamic, and is
done at execution time.
Paging is a memory management scheme that permits the physical-address space of a process to
be non-contiguous. In the case of paging, physical memory is broken into fixed-sized blocks
called frames and logical memory is broken into blocks of the same size called pages.
When the bit is set to valid, this value indicates that the associated page is in the process’s
logical address space, and is thus a legal page. If the bit is said to invalid, this value indicates that
the page is not in the process’s logical address space. Using the valid-invalid bit traps illegal
addresses.
14. A Program containing relocatable code was created, assuming it would be loaded at
address 0. In its code, the program refers to the following addresses: 50,78,150,152,154.
If the program is loaded into memory starting at location 250, how do those addresses have
to be adjusted?
All addresses need to be adjusted upward by 250.So the adjusted addresses would be 300,
328, 400, 402, and 404.
Virtual memory is a technique that allows the execution of processes that may not be
completely in memory. It is the separation of user logical memory from physical memory. This
separation provides an extremely large virtual memory, when only a smaller physical memory is
available.
Rather than swapping the entire process into main memory, a lazy swapper is used.
A lazy swapper never swaps a page into memory unless that page will be needed.
When starting execution of a process with no pages in memory, the operating system
sets the instruction pointer to the first instruction of the process, which is on a non-memory
resident page, the process immediately faults for the page. After this page is brought into
memory, the process continues to execute, faulting as necessary until every page that it needs is
in memory. At that point, it can execute with no more faults. This schema is pure demand
paging.
Let p be the probability of a page fault (0£p£1). The value of p is expected to be close to
0; that is, there will be only a few page faults. The effective access time is,
ma : memory-access time
This memory holds those pages that are not present in main memory. The secondary
memory is usually a high speed disk. It is known as the swap device, and the section of the disk
used for this purpose is known as swap space.
If no frame is free is available, find one that is not currently being used and free it. A
frame can be freed by writing its contents to swap space, and changing the page table to indicate
that the page is no longer in memory. Now the freed frame can be used to hold the page for
which the process faulted.
22. What is the various Page Replacement Algorithms used for Page Replacement?
PART – B
UNIT – IV
Part – A
1 . What is a File?
A file is a named collection of related information that is recorded on secondary storage. A file
contains either programs or data. A file has certain “structure” based on its type.
File attributes: Name, identifier, type, size, location, protection, time, date
File operations: creation, reading, writing, repositioning, deleting, truncating,
appending, renaming
File types: executable, object, library, source code etc.
A file has certain other attributes, which vary from one operating system to another,
but typically consist of these: Name, identifier, type, location, size, protection, time, date and
user identification.
Several pieces of information are associated with an open file which may be:
File open
Disk
Access
pointer
location
rights
count
of the file
6. What is Directory?
The device directory or simply known as directory records information-
such as
name, location, size, and type for all files on that particular partition. The directory
can be viewed as a symbol table that translates file names into their directory entries.
8. What are the most common schemes for defining the Logical Structure of
aDirectory?
The most common schemes for defining the logical structure of a directory
-Level Directory
-level Directory
-Structured Directories
-Graph Directories
Graph Directory
In the two-level directory structure, each user has own user file directory (UFD). Each
UFD has a similar structure, but lists only the files of a single user. When a job starts the
system’s master file directory (MFD) is searched. The MFD is indexed by the user name or
account number, and each entry points to the UFD for that user.
10. What is a Path Name?
A pathname is the path from the root through all subdirectories to a specified file. In a
two-level directory structure a user name and a file name define a path name.
The way to split ‘m’ frames among ‘n’ processes is to give everyone an equal share,
m/n frames. For instance, if there are 93 frames and 5 processes, each process will get 18 frames.
The leftover 3 frames could be used as a free-frame buffer pool. This scheme is called equal
allocation.
13. What is the cause of Thrashing? How does the system detect thrashing? Once it detects
thrashing, what can the system do to eliminate this problem?
14. If the average page faults service time of 25 ms and a memory access time of
100ns.Calculate the effective access time.
Effective access time = (1-p)*ma + p*page fault time
= (1-p)*100+p*25000000
= 100-100p+25000000*p
= 100 + 24999900p
For some page replacement algorithms, the page fault rate may increase as the
number of allocated frames increases.
The locality model states that, as a process executes, it moves from locality to
locality. Locality is of two types.
` The file system is composed of many different levels. Each level in the design uses
the feature of the lower levels to create new features for use by higher levels.
Application programs
-organization module
Several on-disk and in-memory structures are used to implement a file system
-disk structure include
Three major methods of allocating disk space which are widely in use are
entation
Rotational latency is the additional time waiting for the disk to rotate the desired sector to
the disk head. The disk bandwidth is the total number of bytes transferred, divided by the time
between the first request for service and the completion of the last transfer.
The free-space list is implemented as a bit map or bit vector. Each block is
represented by 1 bit. If the block is free, the bit is 1; if the block is allocated, the bit is 0.
A buffer is a memory area that stores data while they are transferred between two devices
or between a device and an application. Buffering is done for three reasons,
-transfer sizes
emantics for application I/O.
PART - B
UNIT – V
PART – A
1. Define Caching.
A cache is a region of fast memory that holds copies of data. Access to the cached copy is
more efficient than access to the original. Caching and buffering are distinct functions, but
sometimes a region of memory can be used for both purposes.
2. Define Spooling.
A spool is a buffer that holds output for a device, such as printer, that cannot accept
interleaved data streams. When an application finishes printing, the spooling system queues the
corresponding spool file for output to the printer. The spooling system copies the queued
spool files to the printer one at a time.
-SCAN Scheduling
Before a disk can store data, it must be divided into sectors that the disk controller can
read and write. This process is called low-level formatting or physical formatting. Low-level
formatting fills the disk with a special data structure for each sector. The data structure for a
sector consists of a header, a data area, and a trailer.
For a computer to start running when powered up or rebooted it needs to have an initial
program to run. This bootstrap program tends to be simple. It finds the operating system on
the disk loads that kernel into memory and jumps to an initial address to begin the operating
system execution. The full bootstrap program is stored in a partition called the boot blocks, at
fixed location on the disk. A disk that has boot partition is called boot disk or system disk.
Low-level formatting also sets aside spare sectors not visible to the operating system.
The controller can be told to replace each bad sector logically with one of the spare sectors. This
scheme is known as sector sparing or forwarding.
There would be multiple paths to the same file, which could confuse users or
encourage mistakes. (Deleting a file with one path deletes the file in all the other paths.)
10. Why must the bit map for file allocation be kept on mass storage rather than in main
memory?
In case of system crash (memory failure), the free-space list would not be lost as it would
be if the bit map had been stored in main memory.
11. What criteria should be used in deciding which strategy is best utilized for a
particular file?
6. Explain in detail the allocation and freeing the file storage space.
8. Discuss with diagrams the following three disk scheduling: FCFS, SSTF, C-SCAN.
9. Compare and contrast the FREE SPACE and SWAP SPACE management.
11. Describe the most common schemes for defining the logical structure of a Directory.
Fourth Semester
(Regulation 2008)
PART B — (5 × 16 = 80 Marks)
11. (a) (i) Explain how hardware protection can be achieved and discuss in detail the dual mode
of operations. (Marks 8)
Or
(b) What is meant by a process? Explain states of process with neat sketch and discuss the
process state transition with a neat diagram. (Marks 16)
12. (a) What is a critical section? Give examples. What are the minimum requirements that
should be satisfied by a solution to critical section problem? Write Peterson Algorithm for 2-
process synchronization to critical section problem and discuss briefly. (Marks 16)
Or
abcdabcdabcd
P0 0 0 1 2 0 0 1 2 1 5 2 0
P1 1 0 0 0 1 7 5 0
P2 1 3 5 4 2 3 5 6
P3 0 6 3 2 0 6 5 2
P4 0 0 1 4 0 6 5 6
13. (a) Given memory partition of 100 KB, 500 KB, 200 KB and 600 KB (inorder). Show with
neat sketch how would each of the first-fit, best-fit and worst fit algorithms place processes of
412 KB, 317 KB, 112 KB and 326 KB (in order). Which algorithm is most efficient in memory
allocation? (Marks 16)
Or
(b) Explain the concept of demand paging. How can demand paging be implemented with virtual
memory? (Marks 16)
14. (a) (i) Explain various file allocation methods in detail. (Marks 8)
(ii) What are the possible structures for directory? Discuss them in detail. (Marks 8)
Or
(b) Explain in detail the free space management with neat diagram. (16)
15. (a) Explain in detail various disk scheduling algorithms with suitable example. (16)
Or
(b) Write short notes on the following :
(i) I/O Hardware (Marks 8)
PART B — (5 × 16 = 80 marks)
11. (a) (i) Briefly illustrate how a server communicates to a client with a java-based sockets
program. (12)
(ii) Briefly demonstrate how Remote Method Invocation process works. (4)
Or
(b) (i) Write about the three common types of threading implementation. (6)
(ii) Discuss the threading issues which are considered with multithreaded programs. (10)
12. (a) Explain briefly any four CPU scheduling algorithms with examples. (16)
Or
(b) (i) Write short notes on readers-writers problem and the dining philosophers problem. (8)
(ii) Explain the two solutions of recovery from deadlock. (8)
13. (a) Explain the most commonly used techniques for structuring the page table. (16)
Or
(b) Explain FIFO, Optimal and LRU page replacement algorithms. (16)
14. (a) Explain the two-level directory and three-structured directory. (16)
Or
(b) Give short notes on (16)
(i) Linux file system
(ii) windows XP file system
15. (a) Briefly describe the services which are provided by the kernel’s I/O subsystem. (16)
Or
(b) Describe the different forms of disk scheduling. (16)
B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2011.
Fourth Semester
Computer Science and Engineering
CS 2254 – OPERATING SYSTEMS
(Common to Information Technology)
(Regulation 2008)
Time : Three hours Maximum : 100 marks
Answer ALL questions.
PART A — (10 × 2 = 20 marks)
1. What does the CPU do when there are no user programs to run?
2. What is the principal advantage of the multiprogramming?
3. Define Mutual Exclusion.
4. What is Semaphore?
5. What is page frame?
6. What is internal fragmentation?
7. A direct or sequential access has a fixed file-size S-byte record. At what logical location, the
first byte of record N will start?
8. Give an example of a situation where variable-size records would be useful.
9. Writable CD-ROM media are available in both 650 MB and 700 MB versions. What is the
principle disadvantage, other than cost, of the 700 MB version?
10. Which disk scheduling algorithm would be best to optimize the performance of a RAM disk?
PART B — (5 × 16 = 80 marks)
11. (a) (i) Explain the important services of an operating system. (8)
(ii) Discuss in detail the concept of virtual machines, with neat sketch. (8)
Or
(b) Write detailed notes on process control and file manipulation. (16)
12. (a) Explain in detail about any two CPU scheduling algorithms with suitable examples. (16)
Or
(b) (i) What is a deadlock? What are the necessary conditions for a deadlock to occur? (6)
(ii) How can a system recover from deadlock? (10)
13. (a) Explain about contiguous memory allocation with neat diagram. (16)
Or
(b) What do you mean by paging? Discuss in detail about structure of page tables with
appropriate examples. (16)
14. (a) Write a detailed note on various file access methods with neat sketch.(16)
Or
(b) Discuss the different file allocation methods with suitable example. (16)
15. (a) Describe the important concepts of application I/O interface. (16)
Or
(b) Explain any two disk scheduling algorithms with suitable example. (16)