CS8493-OS FULL MATERIAL
CS8493-OS FULL MATERIAL
1
Linux System — Design Principles, Kernel Modules, Process Management,
Scheduling, Memory Management, Input-Output Management, File
System, Inter-process Communication; Mobile OS — iOS and Android —
Architecture and SDK Framework, Media Layer, Services Layer, Core OS
Layer, File System.
2
UNIT I OPERATING SYSTEM OVERVIEW
Hardware
Operating system
The application programs
Users
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,
3
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.
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.
The common output devices were line printers, tape drives, and card
punches.
The user did not interact directly with the computer systems.
4
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.
A pool of jobs on disk allows the OS to select which job to run next,
toincrease CPU utilization.
5
Multiprogramming increases CPU utilization by organizing jobs such that
the CPU always has one to execute.
The idea is as follows: The operating system keeps several jobs in
memory simultaneously. This set of jobs is a subset of the jobs kept in
the job pool. The operating system picks and begins to execute one of
the jobs in the memory.
Timesharing Systems
Time sharing (or multitasking) is a logical extension of multiprogramming.
The CPU executes multiple jobs by switching among them, but the
switches occur so frequently that the users can interact with each
program while it is running.
A time-shared operating System allows many users to share the
computer simultaneously Since each time-shared system tends to be
short, only a little CPU time is needed for each user.
As the system switches rapidly from one user to the next, each user is
given theimpression that the entire computer system is dedicated to her
use, even though it is being shared among many users.
6
Operating systems for these computers have benefited from the
development of operating systems for mainframes in several ways.
1.5 Multiprocessor Systems
7
1.6 Distributed Systems
In contrast to the tightly coupled systems, the processors do not share
memory or a clock. Instead , each processor has its own local memory.
The processors communicate with one another through various
communication lines, such as high speed buses or telephone lines. These systems
are usually referred to as loosely coupled systems, or distributed systems.
Resource Sharing
Computation speedup
Reliability
Communication
1.7 Real-Time Systems
This goal requires that all delays in the system be bounded, from the
retrievalof stored data to the time that it takes the operating system to
finish any request made of it.
OPERATING SYSTEM COMPONENTS
There are eight major operating system components. They are:
Process management
8
Main-memory management
File management
I/O-system management
Secondary-storage management
Networking
Protection system
Command-interpreter system
(i) Process Management
A process needs certain resources-including CPU time, memory, files, and
I/Odevices-to accomplish its task.
9
Providing mechanisms for process communication
Providing mechanisms for deadlock handling
(ii) Main – Memory Management
Keeping track of which parts of memory are currently being used and by
whom.
(iii) File Management
File management is one of the most visible components of an
operatingsystem.
10
(iv)I/O System management
specific hardware devices from the user. This is done using the I/O
subsystem.
because the data that it holds are lost when power is lost, the computer
system must provide secondary storage tobackupmainmemory.
Free-space management
Storage allocation
Disk Scheduling
(vi)Networking
11
ü The processors in the system are connected through a communication
network, which can be configured in a number of different ways.
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.
12
BASIC ELEMENTS
1. Main Memory
14
Main memory (GB): Main memory is arguably the most used memory.
When discussing computer algorithms such as quick sort, balanced binary
sorted trees, or fast Fourier transform, one typically assumes that the
algorithm operates on data stored in the main memory. The main memory is
reasonably fast, with access speed around 100 nanoseconds. It also offers
larger capacity at a lower cost. Typical main memory is in the order of 10
GB. However, the main memory is volatile.
Secondary storage (TB): Secondary storage refers to nonvolatile data storage
units that are external to the computer system. Hard drives and solid state
drives are examples of secondary storage. They offer very large storage
capacity in the order of terabytes at very low cost. Therefore, database
servers typically have an array of secondary storage devices with data stored
distributed and redundantly across these devices. Despite the continuous
improvements in access speed of hard drives, secondary storage devices are
several magnitudes slower than main memory. Modern hard drives have
access speed in the order of a few milliseconds.
Tertiary storage (PB): Tertiary storage refers storage designed for the
purpose data backup. Examples of tertiary storage devices are tape drives are
robotic driven disk arrays. They are capable of petabyte range storage, but
have very slow access speed with data access latency in seconds or minutes.
CACHE MEMORY
Cache (pronounced cash) memory is extremely fast memory that is built
into a computer’s central processing unit (CPU), or located next to it on a
separate chip. The CPU uses cache memory to store instructions that are
repeatedly required to run programs, improving overall system speed. The
advantage of cache memory is that the CPU does not have to use the
motherboard’s system bus for data transfer. Whenever data must be passed
through the system bus, the data transfer speed slows to the
motherboard’s capability. The CPU can process data much faster by
avoiding the bottleneck created by the system bus.
As it happens, once most programs are open and running, they use very few
resources. When these resources are kept in cache, programs can operate
more quickly and efficiently. All else being equal, cache is so effective in
system performance that a computer running a fast CPU with little cache can
have lower benchmarks than a system running a somewhat slower CPU with
15
more cache. Cache built into the CPU itself is referred to as Level 1 (L1)
cache. Cache that resides on a separate chip next to the CPU is called Level
2 (L2) cache. Some CPUs have both L1 and L2 cache built-in and designate
the separate cache chip as Level 3 (L3) cache.
Cache that is built into the CPU is faster than separate cache, running at the
speed of the microprocessor itself. However, separate cache is still roughly
twice as fast as Random Access Memory (RAM). Cache is more expensive
than RAM, but it is well worth getting a CPU and motherboard with built-in
cache in order to maximize system performance.
16
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.
1. Modes of operation
1.1Burst mode
The cycle stealing mode is used in systems in which the CPU should not be
disabled for the length of time needed for burst transfer modes.
In the cycle stealing mode, the DMA controller obtains access to the system
bus the same way as in burst mode, using BR (Bus Request) and BG (Bus
Grant) signals, which are the two signals controlling the interface between
the CPU and the DMA controller.
However, in cycle stealing mode, after one byte of data transfer, the control of
the system bus is deasserted to the CPU via BG.
17
The transparent mode takes the most time to transfer a block of data, yet it
isalso the most efficient mode in terms of overall system performance. The
DMA controller only transfers data when the CPU is performing operations
that do not use the system buses.
It is the primary advantage of the transparent mode that the CPU never
stopsexecuting its programs and the DMA transfer is free in terms of time.
The disadvantage of the transparent mode is that the hardware needs to
determine when the CPU is not using the system buses, which can be complex.
MULTIPROCESSOR AND MULTICORE ORGANIZATION
18
main advantage of multiprocessor system is to get more work done in a shorter
period of time. Moreover, multiprocessor systems prove more reliable in the
situations of failure of one processor. In this situation, the system with
multiprocessor will not halt the system; it will only slow it down.
In order to employ multiprocessing operating system effectively, the computer
system must have the followings:
1. Motherboard Support:
2. Processor Support:
19
In order to provide safe access to the resources shared among multiple
processors, they need to be protected by locking scheme. The purpose
of a locking is to serialize accesses to the protected resource by
multiple processors. Undisciplined use of locking can severely
degrade the performance of system.
This form of contention can be reduced by using locking scheme,
avoiding long critical sections, replacing locks with lock-free
algorithms, or, whenever possible, avoiding sharing altogether.
20
A set of procedures that enable a group of people to use a computer
system.
A program that controls the execution of application programs
An interface between applications and hardware
Functions
Usage
Computer system
Control
Support
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
Control
21
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:
For the end users - provides the interface to the application programs
Problems
22
2. Simple Batch Systems
Improve the utilization of computers.
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.
23
New features:
Memory management - to have several jobs ready to run, they must be kept
in main memory
4. Time-Sharing Systems
Multiprogramming systems: Several programs use the computer system.
Characteristics:
24
Using multiprogramming to handle multiple interactive
jobs Processor’s time is shared among multiple users
Multiple users simultaneously access the system through terminals
5. Operating-System Services
The OS provides certain services to programs and to the users of those
programs.
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:
4. Communications :
5. Error detection:
25
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:
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:
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
26
2. Windows 95/98/Me
3. Windows Xp
4. Windows Vista
5. Windows 7
6. windows 8
7. MULTICS derivatives
1. UNIX
OpenBSD
2. Xenix
3. Linux
6. VSTa
7. Mac OSX
8. MIPS RISC/os
9. RISC iX
8. VMS derivatives
27
1. VMS
1. OpenVMS
2. OS/2
1. eComStation
1. ReactOS
9. MacOS derivatives
4. Mac OS
1. Mac OS 9
1. KeyKOS
1. EROS
2. Coyotos
3. CapROS
2. OS/400
4. AROS
28
1. AmigaOS 4.x
2. MorphOS
2. ITS
3. BeOS
COMPUTER SYSTEM ORGANIZATION
29
Provides the file system, CPU scheduling, memory management, and other
operating-system functions; a large number of functions for one level.
1.3 Layered Approach
The operating system is divided into a number of layers (levels), each built on
top of lower layers. The bottom layer (layer 0), is the hardware; the highest
(layer N) is the user interface.
An OS layer is an implementation of an abstract object that is the
encapsulation of data and operations that can manipulate those data. These
operations (routines) can be invoked by higher-level layers. The layer itself
can invoke operations on lower-level layers.
Layered approach provides modularity. With modularity, layers are selected
such that each layer uses functions (operations) and services of only lower-
level layers.
Each layer is implemented by using only those operations that are provided
lower level layers.
The major difficulty is appropriate definition of various layers.
In order to ensure the proper execution of the operating system, we must be
able todistinguish between the execution of operating-system code and user
defined code. The approach taken by most computer systems is to provide
hardware support that allows us to differentiate among various modes of
execution.
31
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.
2.2Timer
2. file management
3. device management
4. information maintenance
32
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
3. Device Management
33
Get time or date, set time or date
Get system data, set system data
Get process, file, or device attributes
5. Communications
PROCESSES
Aprocessis a program in execution.
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
35
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.
2. Process Hierarchies
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.
PROCESS SCHEDULING
The objective of multiprogramming is to have some process running at all
times, so as to maximize CPU utilization.
Scheduling Queues
There are 3 types of scheduling queues .They are :
Job Queue
Ready Queue
36
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 create a new subprocess and wait for its termination.
Schedulers
37
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
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 An I\O-bound process spends more of its time doing I/O than it spends
doing computations.
38
The Medium term Scheduler
ü At some later time, the process can be reintroduced into memory and
its execution can be continued where it left off. This scheme is called
swapping.
OPERATIONS ON PROCESSES
Process Creation
A process may create several new processes, during the course of execution.
The creating process is called a parent process, whereas the new processes are
called the children of that process.
39
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 process is a duplicate of the parent process.
The child process has a program loaded into it.
Process Termination
A process terminates when it finishes executing itsfinal statement and asks the
operating system to delete it by using the exit system call.
At that point, the process may return data (output) to its parent process (via
the wait system call).
A process can cause the termination of another process via an appropriate
system call.
A parent may terminate the execution of one of its children for a variety of
reasons, such as these:
The child has exceeded its usage of some of the resources that it has been
allocated.
The task assigned to the child is no longer required.
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
40
Operating systems provide the means for cooperating processes to
communicate with each other via an interprocess communication (PC)
facility.
IPC provides a mechanism to allow processes to communicate and to
synchronize their actions.IPC is best provided by a message passing system.
Basic Structure:
If processes P and Q want to communicate, they must send messages to and
receive messages from each other; a communication link must exist between
them.
There are several methods for logically implementing a link and the
operations:
1. Direct or indirect communication
2. Symmetric or asymmetric communication
3. Automatic or explicit buffering
4. Send by copy or send by reference
5. Fixed-sized or variable-sized messages
1. Naming
Processes that want to communicate must have a way to refer to each other.
41
A link is associated with exactly two processes.
Symmetry in addressing
Asymmetry in addressing
In symmetry in addressing, the send and receive primitives are defined as:
send(P, message) Send a message to process P
receive(Q, message) Receive a message from Q
In asymmetry in addressing , the send & receive primitives are
defined as:
send (p, message) send a message to process p
receive(id, message) receive message from any process,
id is set to the name of the process with which communication has taken place
or ports.With indirect communication, the messages are sent to and received from
mailboxes,
A link has some capacity that determines the number of message that can
reside in it temporarily. This property can be viewed as a queue of messages
attached to the link.
Bounded capacity: The queue has finite length n. Thus at most n messages can
reside in it.
Unbounded capacity: The queue has potentially infinite length. Thus any
number of messages can wait in it. The sender is never delayed.
1.4 Synchronization
Blocking Send - The sender blocks itself till the message sent by it is received
by the receiver.
Non-blocking Send - The sender does not block itself after sending the
message but continues with its normal operation.
43
THREADS
A thread is the basic unit of CPU utilization.
It is sometimes called as a lightweight process.
It consists 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 resources such as open files and signals.
A traditional or heavy weight process has a single thread of control.
If the process has multiple threads of control, it can do more than one task at
a time.
44
Utilization of MP Architectures
2. User thread and Kernel threads
2.1. User threads
2.2.Kernel threads
45
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 application programmers, there are five areas where multi-core chips
present new challenges:
1. Identifying tasks - Examining applications to find activities
that can be performed concurrently.
46
3. Data splitting - To prevent the threads from interfering with
one another.
1. Data parallelism divides the data up amongst multiple cores ( threads ), and
performs the same task on each subset of the data. For example dividing a large
image up into pieces and performing the same digital image processing on each
piece on different cores.
1. Many-to-One
2. One-to-One
3. Many-to-Many
47
1. Many-to-One:
2.One-to-One:
- Windows 95/98/NT/2000
- OS/2
3. Many-to-Many Model:
48
Thread libraries provide programmers with an API for creating and managing
threads.
The following sections will demonstrate the use of threads in all three systems
for calculating the sum of integers from 0 to N in a separate thread, and
storing the result in a variable "sum".
1. Pthreads
49
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.
2. Java Threads
ALL Java programs use Threads - even "common" single-threaded ones.
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. )
50
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. )
3. Windows Threads
Similar to pThreads. Examine the code example to see the differences, which are
mostly syntactic & nomenclature:
51
PROCESS SYNCHRONIZATION
1. Background
Producer code
item nextProduced;
while( true ) {
/* Produce an item and store it in nextProduced */
nextProduced = makeNewItem( . . . );
/* And then store the item and repeat the loop. */ buffer[ in ]
= nextProduced;
in = ( in + 1 ) % BUFFER_SIZE;
Consumer code
52
item nextConsumed;
while( true ) {
; /* Do nothing */
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.
We could try to overcome this deficiency by introducing a counter variable, as
shown in the following code segments:
53
Unfortunately we have now introduced a new problem, because both the
producer and the consumer are adjusting the value of the variable counter,
which can lead to a condition known as a race condition. In this condition a
piece of code may or may not work correctly, depending on which of two
simultaneous processes executes first, and more importantly if one of the
processes gets interrupted such that the other process runs between important
steps of the first process. ( Bank balance example discussed in class. )
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.
54
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,
(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:
CRITICAL-SECTION PROBLEM
The producer-consumer problem described above is a specific example of a
more general situation known as the critical section problem. The general
idea is that in a number of cooperating processes, each has a critical section
of code, with the following conditions and terminologies:
55
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.
p 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.
56
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. )
57
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,
58
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.
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, however,forthebusylooptobe interruptedwhenthetesistrue,which
prevents the system from hanging forever.
1. Semaphore Usage
S1;
signal( synch );
Because synch was initialized to 0, process P2 will block on the wait until
after P1 executes the call to signal.
2. Semaphore Implementation
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
60
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:
Monitor Usage
A monitor is essentially a class, in which all data is private, and with the special
restriction that only one method within any given monitor object may be active at
the same time. An additional restriction is that monitor methods may only access
62
the shared data within the monitor and any data passed to them as parameters. I.e.
they cannot access any data external to the monitor.
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.)
63
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.
64
Condition variables can be implemented using semaphores as well. For a
condition x,semaphore "x_sem" and an integer "x_count" are introduced,
both initialized to zero. The wait and signal methods are then implemented
as follows. ( This approach to the condition implements the signal-and-wait
option described above for ensuring that only one process at time is active
inside the monitor. )
CPU SCHEDULING
ü Basic Concepts
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.
ü CPU-I/O Burst Cycle
65
Almost all processes alternate between two states in a continuing cycle, as
shown in Figure below :
CPU bursts vary from process to process, and from program to program, but an
extensive study shows frequency patterns similar to that shown in Figure
66
ü CPU Scheduler
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.
Preemptive Scheduling
CPU scheduling decisions take place under one of four conditions:
1. When a process switches from the running state to the waiting
state, such as for an I/O request or invocation of the wait( )
system call.
67
For conditions 1 and 4 there is no choice - A new process must be
selected.
For conditions 2 and 3 there is a choice - To either continue running
the current process, or select a different one.
If scheduling takes place only under conditions 1 and 4, the system is
said to be non-preemptive, or cooperative. Under these conditions,
once a process starts running it keeps running, until it either
voluntarily blocks or until it finishes. Otherwise the system is said to
be preemptive.
Windows used non-preemptive scheduling up to Windows 3.x, and
started using pre-emptive scheduling with Win95. Macs used non-
preemptive prior to OSX, and pre-emptive since then. Note that pre-
emptive scheduling is only possible on hardware that supports a timer
interrupt.
Note that pre-emptive scheduling can cause problems when two
processes share data, because one process may get interrupted in the
middle of updating shared data structures.
Preemption can also be a problem if the kernel is busy implementing
a system call (e.g. updating critical kernel data structures) when the
preemption occurs. Most modern UNIX deal with this problem by
making the process wait until the system call has either completed or
blocked before allowing the preemption Unfortunately this solution is
problematic for real-time systems, as real-time response can no longer
be guaranteed.
Some critical sections of code protect themselves from concurrency
problems by disabling interrupts before entering the critical section
and re-enabling interrupts on exiting the section. Needless to say, this
should only be done in rare situations, and only on very short pieces
of code that will finish quickly, (usually just a few machine
instructions.)
Dispatcher
68
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.
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.
69
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.
Technically this algorithm picks a process based on the next shortest CPU burst,
not the overall process time.
70
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
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:
72
Priorities can be assigned either internally or externally. Internal
priorities are assigned by the OS using criteria such as average burst
time, ratio of CPU to I/O activity, system resource use, and other
factors available to the kernel. External priorities are assigned by
users, based on the importance of the job, fees paid, politics, etc.
Round Robin Scheduling
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.
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.
74
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
75
o Aging can also be incorporated, so that a job that has waited for
a long time can get bumped up into a higher priority queue for a
while.
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.
76
3. Release: The process releases the resource.
1. Deadlock Characterization
Four Necessary conditions for a deadlock
2. Hold and wait: A process must be holding at least one resource and
waiting to acquire additional resources that are currently being held by other
processes.
2. Resource-Allocation Graph
It is a Directed Graph with a set of vertices V and set of edges E.
Rj may have more than one instance represented as a dot with in the square.
77
Sets P,R and E. P = {P1,P2,P3} R = {R1,R2,R3,R4}
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
P1->R1->P2->R3->P3->R2->P1
P2->R3->P3->R2->P2
ü Deadlock Prevention
ü Deadlock Avoidance
78
3. Deadlock Prevention:
This ensures that the system never enters the deadlock state.
Deadlock prevention is a set of methods for ensuring that at least one of the
necessary conditions cannot hold.
By ensuring that at least one of these conditions cannot hold, we can prevent
the occurrence of a deadlock.
Denying Mutual exclusion
o One technique that can be used requires each process to request and
be allocated
79
o Another technique is before it can request any additional resources, it must
release all the resources that it is currently allocated.
Impose a total ordering of all resource types and allow each process
torequest for resources in an increasing order of enumeration.
F(tapedrive)=1,
F(diskdrive)=5,
F(Printer)=12.
Each process can request resources only in an increasing
order of
enumeration.
80
4. Deadlock Avoidance:
Deadlock avoidance request that the OS be given in advance additional
information
concerning which resources a process will request and useduring its
life time.
With this information it can be decided for each request whether or not the
process should wait.
Safe State
81
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.
Similarly, when a resource Rj is released by Pi the assignment edge Rj -> Pi
is reconverted to a claim edge Pi -> Rj
Banker's algorithm
Max: Max[i, j]=k then process Pi may request at most k instances of resource
type Rj
Need : if Need[i, j]=k then process Pi may need K more instances of resource
type Rj Need [i, j]=Max[i, j]-Allocation[i, j]
Safety algorithm
goto step 2
82
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;
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.
5. Deadlock Detection
(i) Single instance of each resource type
ResourceAllocation Graph
83
ii) Several Instance of a resource type
Available : Number of available resources of each type
Allocation : number of resources of each type currently allocated toeach
process
Request : Current request of each process
If Request [i,j]=k, then process Pi is requesting K more instances of resource type
Rj.
1. Initialize work := available
a. Finish[i]=false
b. Requesti<=work
3. Work:=work+allocationi
4. If finish[i]=false
6. Deadlock Recovery
84
1. Process Termination
1. Abort all deadlocked processes.
2. Abort one deadlocked process at a time until the deadlock cycle is
eliminated.
After each process is aborted , a deadlock detection algorithm must be
invoked to determine where any process is still dead locked.
2. Resource Preemption
Preemptive some resources from process and give these resources to other
processes until the deadlock cycle is broken.
85
UNIT III STORAGE MANAGEMENT
3 Execution time: Need hardware support for address maps (e.g., base
and limit
registers).
Logical and physical addresses are the same in compile-time and load-time
address-binding schemes
86
Memory-Management Unit (MMU)
It is a hardware device that maps virtual / Logical address to physical
address.
The user program deals with logical addresses; it never sees the real physical
addresses
Logical address range: 0 to max
Physical address range: R+0 to R+max, where R—value in
relocation.
Dynamic Linking
Linking postponed until execution time & is particularly useful for libraries
Small piece of code called stub, used to locate the appropriate memory
residentlibrary routine or function.
Stub replaces itself with the address of the routine, and executes the routine
Operating system needed to check if routine is in processes Memory
addresses Shared libraries.
Programs linked before the new library was installed will continue using the
older library.
Contiguous Memory Allocation
Each process is contained in a single contiguous section of memory.
Fixed–Partition Method
Variable–Partition Method
Divide memory into fixed size partitions, where each partition has
exactly
one process.
Variable-partition method:
Divide memory into variable size partitions, depending upon the size of the
incoming process.
88
When a process terminates, the partition becomes available for
another process.
Solution:
NOTE: First-fit and best-fit are better than worst-fit in terms of speed and storage
utilization
Fragmentation
89
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:
Solutions:
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 doneif relocation is dynamic and done at execution time.
90
Segment table–maps two-dimensional physical addresses; each table entry
has:
Base–contains the starting physical address where the segments
reside in memory
Sharing.
shared segments
same segment number
91
Allocation.
read/write/execute privileges
Protection bits associated with segments; code sharing occurs at segment
level
92
93
Another advantage of segmentation involves the sharing of code or data.
Each process has a segment table associated with it, which the dispatcher uses
to define the hardware segment table when this process is given the CPU.
Segments are shared when entries in the segment tables of two different
processespoint to the same physical location.
The IBM OS/ 2.32 bit version is an operating system running on top of the
Intel 386 architecture. The 386 user segmentation with paging for memory
management. The maximum number of segments per process is 16 KB, and
each segment can be as large as 4 gigabytes.
The local-address space of a process is divided into two partitions.
The first partition consists of up to 8 KB segments that are private to that
process.
The second partition consists of up to 8KB segments that are shared
among all the processes.
Information about the first partition is kept in the local descriptor table
(LDT), information about the second partition is kept in the global descriptor
table (GDT).
Each entry in the LDT and GDT consist of 8 bytes, with detailed information
about a particular segment including the base location and length of the segment.
The logical address is a pair (selector, offset) where the selector is a16-bit
number:
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.
94
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.
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.
PAGING
95
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.
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.
96
Paging example for a 32-byte memory with 4-byte pages
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.
97
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.
98
o It contains the recently or frequently used page table entries. o It has
two parts: Key (tag) & Value.
o More expensive.
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).
99
Memory protection implemented by associating protection bit with each frame
Valid-invalid bit attached to each entry in the page table:
“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
100
b) Hashed 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.
Each entry in hash table contains a linked list of elements that hash to the same
location. Each entry consists of;
101
(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.
It has one entry for each real page (frame) of memory & each entry consists of
thevirtual address of the page stored in that real memory location, with
information about the process that owns that page. So, only one page table is in the
system.
102
When a memory reference occurs, part of the virtual address, consisting of
<Process-id,
(ii) If no match is found, then an illegal address access has been attempted.
103
o Shared code must appear in same location in the logical address
space of all processes
o Demand segmentation
Demand Paging
104
It is similar to a paging system with swapping.
Demand Paging - Bring a page into memory only when it is needed
To execute a process, swap that entire process into memory. Rather than
swapping
the entire process into memory however, we use Lazy Swapper
Lazy Swapper - Never swaps a page into memory unless that page will be
needed.
Advantages
Faster response
More users
Basic Concepts:
Instead of swapping in the whole processes, the pager brings only those
necessarypages into memory. Thus,
o It avoids reading into memory pages that will not be used anyway.
105
o Reduce the swap time.
To differentiate between those pages that are in memory & those that are on
the disk we use the Valid-Invalid bit
Valid-Invalid bit
invalid page
Page Fault
b) If the reference is valid then the page has not been yet brought into
main memory.
5. Reset the page table to indicate that the page is now in memory.
106
Never bring a page into memory until it is required. We could start a process with
no pages in memory.
When the OS sets the instruction pointer to the 1st instruction of the process,
which is on the non-memory resident page, then the process immediately
faults for the page.
After this page is bought into the memory, the process continue to execute,
faulting as necessary until every page that it needs is in memory.
4. Check whether the reference was legal and find the location of
page on disk.
107
a. Wait in a queue until read request is serviced.
10. Reset the page table to indicate that the page is now in memory.
We can free a frame by writing its contents to swap space & changing the
page table toindicate that the page is no longer in memory.
Then we can use that freed frame to hold the page for which the process
faulted.
Basic Page Replacement
108
- Write the victim page to the disk, change the page & frame tables
accordingly.
3. Read the desired page into the (new) free frame. Update the page and frame
tables.
o If the bit is set, we know that the page has been modified & in this case
we must write that page to the disk.
o If the bit is not set, then if the copy of the page on the disk has not been
overwritten, then we can avoid writing the memory page on the disk
as it is already there.
This algorithm associates with each page ,the time when that page was
brought in.
Example:
110
Drawback:
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Here the no. of page faults increases when the no.of frames increases .This is
called as
Belady’s Anomaly.
Optimal page replacement algorithm
Replace the page that will not be used for the longest period of time.
Example:
111
Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1
Drawback:
Replace the page that has not been used for the longest period of time.
Example:
Every page table entry has a time-of-use field and a clock or counter is
associated with the CPU.
When a page needs to be replaced, replace the page with the smallest
counter
value.
2. Stack
When a page needs to be replaced, replace the page that is at the bottom of
the stack.(LRU page).
Use of A Stack to Record The Most Recent Page References
Reference bit
113
With each page associate a reference bit, initially set to 0
When page is referenced, the bit is set to 1
When a page needs to be replaced, replace the page whose reference bit is 0
The order of use is not known , but we know which pages were used and
which were not used.
114
When a page gets a second chance, its reference bit is cleared and arrival
time isreset to current time.
Hence a second chance page will not be replaced until all other pages are
replaced.
(iii) Enhanced Second Chance Algorithm
It is based on the argument that the page with the smallest count was probably
just brought in and has yet to be used.
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.
115
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.
Working set is the set of pages in the most recent page references is the
working set
window.
116
D=WSSi
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
117
Page Size
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
118
One of the responsibilities of the operating system is to use the hardware
efficiently.
For the disk drives,
1. Disk scheduling
1.1 FCFS 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
119
head position.
The disk head starts at one end of the disk, and moves toward the other end,
servicing requests as it reaches each cylinder, until it gets to the other end of the
disk. At the other end, the direction of head movement is reversed, and servicing
continues. The head continuously scans back and forth across the disk.
120
Elevator algorithm: Sometimes the SCAN algorithm is called as the elevator
algorithm, since the disk arm behaves just like an elevator in a building, first
servicing all the requests going up, and then reversing to service requests the other
way.
Variant of SCAN designed to provide a more uniform wait time. It moves the head
from one end of the disk to the other, servicing requests along the way. When the
head reaches the other end, however, it immediately returns to the beginning of the
disk, without servicing any requests on the return trip.
121
1.5 LOOK Scheduling
Both SCAN and C-SCAN move the disk arm across the full width of the disk. In
this, the arm goes only as far as the final request in each direction. Then, it reverses
direction immediately, without going all the way to the end of the disk.
2. Disk Management
Disk Formatting:
122
Low-level formatting or physical formatting:
Before a disk can store data, the sector is divided into various partitions. This
process is called low-level formatting or physical formatting. It fills the disk
with a special data structure for each sector.
The data structure for a sector consists of
o Header,
Ø Trailer.
The header and trailer contain information used by the disk controller, such as
a sector number and an error-correcting code (ECC).
This formatting enables the manufacturer to
Ø Test the disk and
To use a disk to hold files, the operating system still needs to record its own
data structures on the disk. It does so in two steps.
(a) The first step is Partition the disk into one or more groups of cylinders.
Among the partitions, one partition can hold a copy of the OS‘s executable code,
while another holds user files.
(b) The second step is logical formatting .The operating system stores the
initial file-system data structures onto the disk. These data structures may include
maps of free and allocated space and an initial empty directory.
Boot Block:
123
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
ü Finds the operating system kernel on disk,
Advantages:
reset.
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:
124
Method 1: “Handled manually
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:
ü The oper ating system tries to read logical block 87.
ü The controller calculates the ECC and finds that the sector is bad.
ü 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.
ü After that, whenever the system requests logical block 87, the request is
translated into the replacement sector's address by the controller.
Method 3: “sector slipping”
For an example, suppose that logical block 17 becomes defective, and the first
available spare follows sector 202. Then, sector slipping would remap all the
sectors from 17 to 202,moving them all down one spot. That is, sector 202
would be copied into the spare, then sector 201 into 202, and then 200 into
201, and so on, until sector 18 is copied into sector 19. Slipping the sectors
in this way frees up the space of sector 18, so sector 17 can be mapped to it.
FILE SYSTEM STORAGE
1 File Concept
125
A file is a named collection of related information that is recorded on
secondary storage.
Examples of files:
A text file is a sequence of characters organized into lines (and possibly
pages).
A source file is a sequence of subroutines and functions, each of which is
further organized as declarations followed by executable statements. An
object file is a sequence of bytes organized into blocks understandable by
the system’s linker. An executable file is a series of code sections that the
loader can bring into memory and execute.
2 File Attributes
126
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.
3 File Operations
Creating a file
Reading a file
Repositioning within a file
Deleting a file
Truncating a file
4 File Types
127
FILE SHARING AND PROTECTION
1. MULTIPLE USERS:
When an operating system accommodates multiple users, the issues of file sharing,
file naming and file protection become preeminent.
The system either can allow user to access the file of other users by default, or
it may require that a user specifically grant access to the files.
These are the issues of access control and protection.
To implementing sharing and protection, the system must maintain more file
and directory attributes than a on a single-user system.
128
The owner is the user who may change attributes, grand access, and has the
most control over the file or directory.
The group attribute of a file is used to define a subset of users who may share
access to the file.
Most systems implement owner attributes by managing a list of user names
and associated user identifiers (user Ids).
When a user logs in to the system, the authentication stage determines the
appropriate
user ID for the user. That user ID is associated with all of user’s processes
and threads. When they need to be user readable, they are translated, back to
the user name via the user name list.
129
separate operations (essentially a wrapper for ftp) are used to transfer files.
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.
• Client identification is more difficult. Clients can be specified by
their network name or other identifier, such as IP address, but these can be
spoofed (or imitate). An unauthorized client can spoof the server into
deciding that it is authorized, and the unauthorized client could be allowed
access.
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:
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.
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:
131
o Its name may not be reused and its contents may not be altered.
FILE PROTECTION
2. Types of Access
Complete protection is provided by prohibiting access.
Free access is provided with no protection.
Both approaches are too extreme for general use.
What is needed is controlled access.
5. Delete: Delete the file and free its space for possible reuse.
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.
This technique has two undesirable consequences:
• Constructing such a list may be a tedious and unrewarding task, especially if we
do not know in advance the list of users in the system.
• 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.
FILE SYSTEM STRUCTURE
133
All disk I/O is performed in units of one block (physical record) size which
will exactlymatch the length of the desired logical record.
For example, the UNIX operating system defines all files to be simply a
tream ofbytes. Each byte is individually addressable by its offset from the
beginning (or end) of the file. In this case, the logical records are 1 byte. The
file system automatically packs and unpacks bytes into physical disk
blocks – say, 512 bytes per block – as necessary.
The logical record size, physical block size, and packing technique determine
how many logical records are in each physical block. The packing can be
done either by the user’s application program or by the operating system.
1. Access Methods
1. Sequential Access
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
134
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
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
Other access methods can be built on top of a direct – access method these
methods generally involve the construction of an index for the file. The index
like an index in the back of a book contains pointers to the various blocks in
135
find a record in the file. We first search the index, and then use the pointer to
access the file directly and the find the desired record.
With large files, the index file itself may become too large to be kept
inmemory. 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.
DIRECTORY STRUCTURE
There are five directory structures. They are
Single-level directory
Two-level directory
Tree-Structured directory
Disadvantage:
136
When the number of files increases or when the system has more than one user,
since all files are in the same directory, they must have unique names.
Directory
137
A path name is the path from the root, through all the subdirectories to a
specified file.
One bit in each directory entry defines the entry as a file (0) or as a
subdirectory (1).
Path names can be of two types: absolute path names or relative path names.
An absolute path name begins at the root and follows a path down to the
specified file, giving the directory names on the path.
4. Acyclic Graph Directory.
An acyclic graph is a graph with no cycles.
To implement shared files and subdirectories this directory structure is used.
An acyclic – graph directory structure is more flexible than is a simple tree
structure, but it is also more complex. In a system where sharing is
implemented by symbolic link, this situation is somewhat easier to handle.
The deletion of a link does not need to affect the original file; only the link is
removed.
138
Another approach to deletion is to preserve the file until all references to it
are deleted.
ALLOCATION METHODS
The main problem is how to allocate space to these files so that disk space is
utilized effectively and files can be accessed quickly .
139
1. Contiguous Allocation
2. Linked Allocation
3. Indexed Allocation
1. Contiguous Allocation
The contiguous–allocation method requires each file to occupy a set
ofcontiguous blocks on the disk.
Contiguous allocation of a file is defined by the disk address and length (in
block units)of the first block. If the file is n blocks long and starts at
location b, then it occupies blocks b,. b+1, b+2,….,b+n-1.
The directory entry for each file indicates the address of the starting block and
the length of the area allocated for this file.
Disadvantages:
140
fragmented into a number of holes, no one of which is large enough to
store the data.
2 Determining how much space is needed for a file.
When the file is created, the total amount of space it will need must be found an
allocated how does the creator know the size of the file to be created?
If we allocate too little space to a file, we may find that file cannot be
extended.
The other possibility is to find a larger hole, copy the contents of the file to the
new space, and release the previous space. This series of actions may be
repeated as long as space exists, although it can be time –consuming. However,
in this case, the user never needs to be informed explicitly about what is
happening ; the system continues despite the problem, although more and more
slowly.
Even if the total amount of space needed for a file is known in ad vance pre-
allocation may be inefficient.
A file that grows slowly over a long period (months or years) must be
allocated enough space for its final size, even though much of that space may
be unused for a long time the file, therefore has a large amount of internal
fragmentation.
Internal fragmentation can still be a problem if the extents are too large, and
external fragmentation can be a problem as extents of varying sizes are allocated
and deallocated.
2. Linked Allocation
141
Linked allocation solves all problems of contiguous allocation.
may be scattered any where on the disk. With linked allocation, each file is a
linked list of disk blocks, the disk blocks
The directory contains a pointer to the first and last blocks of the file. For
example, a file of five blocks might start at block 9, continue at block 16, then
block 1, block 10, and finally bock 25.
Each block contains a pointer to the next block. These pointers are not made
available to the user.
There is no external fragmentation with linked allocation, and any free block on
the free space list can be used to satisfy a request.
The size of a file does not need to the declared when that file is created. A file can
continue to grow as long as free blocks are available consequently, it is never
necessary to compacts disk space.
Disadvantages:
142
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.
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.
The 0 is replaced with the end – of – file value, an illustrative example is the
FAT structure for a file consisting of disk blocks 217,618, and 339.
3. Indexed Allocation
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.
144
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
145
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.
2. Size of Index block
If the index block is too small, however, it will not be able to hold enough
pointers for a large file, and a mechanism will have to be available to deal with
this issue:
Linked Scheme: An index block is normally one disk block. Thus, it can be
read and written directly by itself. To allow for large files, we may link together
several index blocks.
Multilevel index: A variant of the linked representation is to use a first level index
block to point to a set of second – level index blocks.
Combined scheme:
o Another alternative, used in the UFS, is to keep the first, say, 15 pointers of
the index block in the file’s inode.
§ The first 12 of these pointers point to direct blocks; that is for small ( no more
than 12 blocks) files do not need a separate index block
ü The single indirect block is an index block, containing not data, but rather the
addresses of blocks that do contain data.
o Then there is a double indirect block pointer, which contains the address of a
block that contain pointers to the actual data blocks. The last pointer would
contain pointers to the actual data blocks.
o The last pointer would contain the address of a triple indirect block.
FREE SPACE MANAGEMENT
Since disk space is limited, we need to reuse the space from deleted files for
new files, if possible.
To keep track of free disk space, the system maintains a free-space list.
146
The free-space list records all free disk blocks – those not allocated to some
file or directory.
To create a file, we search the free-space list for the required amount of space,
and allocate that space to the new file.
When a file is deleted, its disk space is added to the free-space list.
1. Bit Vector
o 001111001111110001100000011100000 …
2. Linked List
147
However, this scheme is not efficient; to traverse the list, we must read each
block, which requires substantial I/O time. The FAT method incorporates
free-block accounting data structure. No separate method is needed.
3. Grouping
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 than1.
Recovery
148
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
Frequently, a special program is run at reboot time to check for and correct
disk inconsistencies.
The consistency checker—a systems program such as chkdsk in MS-DOS
—compares
the data in the directory structure with the data blocks on disk and tries to fix
any inconsistencies it finds. The allocation and free-space-management
algorithms dictate what types of problems the checker can find and how
successful it will be in fixing them.
2. Backup and Restore
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.
A typical backup schedule may then be as follows:
Day 1: Copy to a backup medium all files from the disk. This is called
a full backup.
Day 2: Copy to another medium all files changed since day 1. This is
an incremental backup.
Day 3: Copy to another medium all files changed since day 2.
Day N: Copy to another medium all files changed since day N— 1. Then go
back to Day 1.
149
UNIT V CASE STUDY
LINUX SYSTEM
Basic Concepts
Linux looks and feels much like any other UNIX system; indeed, UNIX
compatibility has been a major design goal of the Linux project. However,
Linux is much younger than most UNIX systems. Its development began
in1991, when a Finnish university student, Linus Torvalds, began
developing a small but self-contained kernel for the 80386 processor, the
first true 32-bitprocessor in Intel’s range of PC-compatible CPUs. of
arbitrary files (but only read-only memory mapping was implemented in
1.0).
A range of extra hardware support was included in this release. Although
still restricted to the Intel PC platform, hardware support had grown to
include floppy-disk and CD-ROM devices, as well as sound cards, a range
of mice, and international keyboards. Floating-point emulation was provided
in the kernel for 80386 users who had no 80387 math coprocessor. System V
UNIX-style interprocess communication (IPC), including shared memory,
semaphores, and message queues, was implemented.
At this point, development started on the 1.1 kernel stream, but numerous
bug-fix patches were released subsequently for 1.0. A pattern was adopted as
the standard numbering convention for Linux kernels. Kernels with an odd
minor-version number, such as 1.1 or 2.5, are development kernels; even
numbered minor-version numbers are stable production kernels. Updates for
the stable kernels are intended only as remedial versions, whereas the
development kernels may include newer and relatively untested
functionality.
As we will see, this pattern remained in effect until version 3.was given a
major version-number increment because of two major new capabilities:
support for multiple architectures, including a 64-bit native Alpha port, and
symmetric multiprocessing (SMP) support. Additionally, the memory
management code was substantially improved to provide a unified cache for
file-system data independent of the caching of block devices.
150
As a result of this change, the kernel offered greatly increased file-system and
virtual memory performance. For the first time, file-system caching was
extended to networked file systems, and writable memory-mapped regions
were also supported. Other major improvements included the addition of
internal kernel threads, a mechanism exposing dependencies between
loadable modules, support for the automatic loading of modules on demand,
file-system quotas, and POSIX-compatible real-time process-scheduling
classes.
Improvements continued with the release of Linux 2.2 in 1999. A port to Ultra
SPARC systems was added. Networking was enhanced with more flexible
firewalling, improved routing and traffic management, and support for TCP
large window and selective acknowledgement. Acorn, Apple, and NT disks
could now be read, and NFS was enhanced with a new kernel-mode NFS
daemon. Signal handling, interrupts, and some I/O were locked at a finer
level than before to improve symmetric multiprocessor (SMP) performance.
The Linux System
Linux kernel is composed entirely of code written from scratch specifically
for the Linux project, much of the supporting software that makes up the
Linux system is not exclusive to Linux but is common to a number of
UNIX-like operating systems. In particular, Linux uses many tools
developed as part of Berkeley’s BSD operating system, MIT’s X Window
System, and the Free Software Foundation’s GNU project.
This sharing of tools has worked in both directions. The main system libraries
of Linux were originated by the GNU project, but the Linux community
greatly improved the libraries by addressing omissions, inefficiencies, and
bugs. Other components, such as the GNU C compiler (gcc), were already of
sufficiently high quality to be used directly in Linux. The network
administration tools under Linux were derived from code first developed for
4.3 BSD, but more recent BSD derivatives, such as FreeBSD, have
borrowed code from Linux in return. Examples of this sharing include the
Intel floating-point-emulation math library and the PC sound-hardware
device drivers.
151
The Linux system as a whole is maintained by a loose network of developers
collaborating over the Internet, with small groups or individuals having
responsibility for maintaining the integrity of specific components.
A small number of public Internet file-transfer-protocol (FTP) archive sites act
as de facto standard repositories for these components. The File System
Hierarchy Standard document is also maintained by the Linux community as
a means of ensuring compatibility across the various system components.
This standard specifies the overall layout of a standard Linux file system; it
determines under which directory names configuration files, libraries,
system binaries, and run-time data files should be stored.
Linux Distributions
In theory, anybody can install a Linux system by fetching the latest revisions
of the necessary system components from the FTP sites and compiling them.
In Linux’s early days, this is precisely what a Linux user had to do. As
Linux has matured, however, various individuals and groups have attempted
to make this job less painful by providing standard, precompiled sets of
packages for easy installation.
These collections, or distributions, include much more than just the basic
Linux system. They typically include extra system-installation and
management utilities, as well as precompiled and ready-to-install packages
of many of the common UNIX tools, such as news servers, web browsers,
text-processing and editing tools, and even games.
The first distributions managed these packages by simply providing a means of
unpacking all the files into the appropriate places. One of the important
contributions of modern distributions, however, is advanced package
management. Today’s Linux distributions include a package-tracking
database that allows packages to be installed, upgraded, or removed
painlessly.
Linux Licensing
The Linux kernel is distributed under version 2.0 of the GNU General Public
License (GPL), the terms of which are set out by the Free Software
152
Foundation. Linux is not public-domain software. Public domain implies
that the authors have waived copyright rights in the software, but copyright
rights in Linux code are still held by the code’s various authors. Linux is free
software, however, in the sense that people can copy it, modify it, use it in
any manner they want, and give away (or sell) their own copies.
The main implication of Linux’s licensing terms is that nobody using Linux, or
creating a derivative of Linux (a legitimate exercise), can distribute the
derivative without including the source code. Software released under the
GPL cannot be redistributed as a binary-only product.
If you release software that includes any components covered by the GPL,
then, under the GPL, you must make source code available alongside any
binary distributions. (This restriction does not prohibit making—or even
selling—binary software distributions, as long as anybody who receives
binaries is also given the opportunity to get the originating source code for a
reasonable distribution charge.)
SYSTEM ADMINISTRATION
In its overall design, Linux resembles other traditional, nonmicrokernel UNIX
implementations. It is a multiuser, preemptively multitasking system with a
full set of UNIX-compatible tools. Linux’s file system adheres to traditional
UNIX semantics, and the standard UNIX networking model is fully
implemented. The internal details of Linux’s design have been influenced
heavily by the history of this operating system’s development.
Although Linux runs on a wide variety of platforms, it was originally
developed exclusively on PC architecture. A great deal of that early
development was carried out by individual enthusiasts rather than by well-
funded development or research facilities, so fromthe start Linux attempted
to squeeze as much functionality as possible from limited resources. Today,
Linux can run happily on a multiprocessor machine with many gigabytes of
main memory and many terabytes of disk space, but it is still capable of
operating usefully in under 16 MB of RAM.
The Linux system is composed of three main bodies of code, in line with most
traditional UNIX implementations:
153
Kernel. The kernel is responsible for maintaining all the important
abstractions of the operating system, including such things as virtualmemory
and processes.
2. Kernel Modules
The Linux kernel has the ability to load and unload arbitrary sections of kernel
code on demand. These loadable kernel modules run in privileged kernel
mode and as a consequence have full access to all the hardware capabilities
of the machine on which they run. In theory, there is no restriction on what a
kernel module is allowed to do. Among other things, a kernel module can
implement a device driver, a file system, or a networking protocol.
Kernel modules are convenient for several reasons. Linux’s source code is
free, so anybody wanting to write kernel code is able to compile a modified
kernel and to reboot into that new functionality. However, recompiling,
relinking, and reloading the entire kernel is a cumbersome cycle to
undertake when you are developing a new driver. If you use kernel modules,
you do not have to make a new kernel to test a new driver—the driver can be
compiled on its own and loaded into the already running kernel. Of course,
once a new driver is written, it can be distributed as a module so that other
users can benefit from it without having to rebuild their kernels.
2. The module loader and unloader, which are user-mode utilities, work
with the module-management system to load a module into memory.
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
156
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.
REQUIREMENTS FOR LINUX SSYTEM
ADMINISTRATOR
v Hardware-Abstraction Layer
The HAL is the layer of software that hides hardware chipset differences from
upper levels of the operating system. The HAL exports a virtual hardware
drivers. Only a single version of each device driver is required for each CPU
architecture, no matter what support chips might be present. Device drivers
map devices and access them directly, but the chipset-specific details of
mapping memory, configuring I/O buses, setting up DMA, and coping with
motherboard-specific facilities are all provided by the HAL interfaces.
v 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.
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.
ü 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.
157
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.
ü Implementation of Synchronization Primitives
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.
158
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.
1. Confirm that the printer you will use to connect to the DPR-1020 is operating
correctly.
2. When you have confirmed that the printer is operating correctly, switch its
power OFF.
4. Using a CAT 5 Ethernet cable, connect the DPR-1020 Ethernet Port (labelled
LAN) to the network.
5. While the printer is turned OFF, connect the USB printer cable to the printer and
then to the USB port on the Print Server.
7. Insert the power adapter’s output plug into the DC 5V power socket on the rear
panel of the Print Server.
8. Connect the other end of the power adapter into a power outlet. This will supply
power to the Print Server. The blue LED on the Print Server’s front panel should
turn on and the Print Server’s self-test will proceed.
Power ON Self-Test
159
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
160
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].
ü 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.
161
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.
162
inexpensive task since virtually all of the source code can be downloaded
from several different FTP or HTTP sites on the Internet. In addition, the
most recent version of Red Hat Linux can be purchased from computer retail
stores for between $25 and $50, depending on whether you purchase the
standard or full version. The retail brand is indeed a worthwhile investment
(vs. the free FTP or HTTP versions) since valuable technical support is
included directly from the Red Hat Linux engineers for at least a year. This
can be very helpful if, for instance, you can not resolve an
installation/configuration problem after consulting the Red Hat Linux
manuals.
This article describes how to put together a Local Area Network (LAN)
consisting of two or more computers using the Red Hat Linux 6.2 operating
system. A LAN is a communications network that interconnects a variety of
devices and provides a means for exchanging information among those
devices. The size and scope of a LAN is usually small, covering a single
building or group of buildings. In a LAN, modems and phone lines are not
required, and the computers should be close enough to run a network cable
between them.
For each computer that will participate in the LAN, you'll need a network
interface card (NIC) to which the network cable will be attached. You will
also need to assign a unique hostname and IP address to each computer in
the LAN (described later in this article), but this requires a basic
understanding of TCP/IP (Transmission Control Protocol/Internet Protocol).
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
163
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:
164
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
VMware Player is a free desktop application that lets you run virtual
machines on a Windows or Linux PC.
VMware Player is the only product on the market that lets you run virtual
machines without investing in virtualization software, making it easier than
ever to take advantage of the security, flexibility, and portability of virtual
machines. VMware Player lets you use host machine devices, such as CD
and DVD drives, from the virtual machine.
166
well as virtual machines that are preconfigured with popular open
source software.
Transform software distribution-Simplify software distribution by
shipping preconfigured software in virtual machines. End users can
experience the benefits of your products immediately, without setup
hassles. VMware Player is ideal for shipping evaluation copies or beta
software. You can package complex, sophisticated applications,
complete with a full working environment, in a virtual machine that
can be used by anyone who downloads VMware Player.
Collaborate with colleagues-VMware Player makes it easy for
support, development, and QA to share customer scenarios in virtual
machines.
1 Log on to your Linux host with the user name you plan to use when
running VMware Player.
5 To use the RPM installer, skip to Step 6. To use the tar installer, follow
these steps:
/tmp/vmware-player-distrib
b Copy the tar archive to a temporary directory on your hard drive, for
example,
/tmp:
cp VMware-<xxxx>.tar.gz /tmp
cd vmware-player-distrib
./vmware-install.pl
i Skip to Step 7.
Adding Guest OS
1. Save the ISO image file in any location accessible to your host. For example:
Note: For best performance, place this image on the host computer's hard drive.
However, to make the ISO image accessible to multiple users, you can also place
the ISO image on a network share drive (Windows) or exported filesystem (Linux).
If your OS install spans multiple discs, you need to use an ISO image of each disc
and place them all of them in a location accessible to the host.
2. Create a new virtual machine. Go to File > New > Virtual Machine.
5. Click Browse, and navigate to the location where you saved the ISO image file.
6. Click next, and proceed through the new virtual machine wizard.
7. Before you click Finish, to create the virtual machine, deselect Power on this
virtual machine after creation.
8. Edit the virtual machine settings so that its virtual CD/DVD device is configured
to use the ISO image rather than the physical CD/DVD drive:
a.Select the tab for the virtual machine you just created.
iii.Click Browse and navigate to where you saved the ISO image file.
e.Click OK.
When you are finished installing the guest OS, you can edit the virtual machine
settings so that it is once more set to use the host computer's physical drive. You
do not need to leave the drive set to connect at power on.
170