I_Unit_OS
I_Unit_OS
DEPARTMENT OF CSBS
21IT1302 / OPERATING SYSTEMS(Lab Integrated)
UNIT I OPERATING SYSTEM OVERVIEW
1.1.1 Basic Elements : A computer consists of processor, memory, I/O components and system bus.
i) Processor: It Controls the operation of the computer and performs its data processing
functions. When there is only one processor, it is often referred to as the central processing
unit.
ii) Main memory: It Stores data and programs. This memory is typically volatile; that is, when
the computer is shut down, the contents of the memory are lost. Main memory is also
referred to as real memory or primary memory.
iii) I/O modules: It moves data between the computer and its external environment. The
external environment consists of a variety of devices, including secondary memory devices
(e. g., disks), communications equipment, and terminals.
iv) System bus: It provides the communication among processors, main memory, and I/O
modules
One of the processor’s functions is to exchange data with memory. For this purpose, it typically
makes use of two internal registers
i) A memory address registers (MAR), which specifies the address in memory for the next
read or write.
ii) A memory buffer register (MBR), which contains the data to be written into
memory or which receives the data read from memory.
➢ An I/O address register (I/O AR) specifies a particular I/O device.
➢ An I/O buffer register (I/O BR) is used for the exchange of data between an I/O module and
the processor.
➢ A memory module consists of a set of locations, defined by sequentially numbered addresses.
➢ An I/O module transfers data from external devices to processor and memory, and vice versa.
It contains internal buffers for temporarily holding data until they can be sent on.
PROCESSOR REGISTERS:
A processor includes a set of registers that provide memory that is faster and smaller than
main memory. Processor registers serve two functions:
i) User-visible registers: Enable the machine or assembly language programmer to minimize
main memory references by optimizing register use.
ii) Control and status registers: Used by the processor to control the operation of the
processor and by privileged OS routines to control the execution of programs.
1. User-Visible Registers:
A user-visible register is generally available to all programs, including application programs as
well as system programs. The types of User visible registers are
i) Data Registers
ii) Address Registers
Data Registers can be used with any machine instruction that performs operations on data.
Address registers contain main memory addresses of data and instructions. Examples of
address registers include the following:
➢ Index register.
➢ Segment pointer
➢ Stack pointer
2. Control and status register:
A variety of processor registers are employed to control the operation of the processor. In
addition to the MAR, MBR, I/OAR, and I/OBR register the following are essential to instruction
execution:
➢ Program counter (PC): Contains the address of the next instruction to be fetched.
➢ Instruction register (IR): It contains the instruction most recently fetched.
All processor designs also include a register or set of registers, often known as the program
status word (PSW) that contains status information. The PSW typically contains condition
codes plus other status information, such as an interrupt enable/disable bit and a kernel/user
mode bit, carry bit, auxiliary carry bit.
1.1.2 Instruction Execution
➢ At the beginning of each instruction cycle, the processor fetches an instruction from
memory.
➢ The instruction contains bits that specify the action the processor is to take. The
processor interprets the instruction and performs the required action.
➢ In general, these actions fall into four categories,
Processor-memory: Data may be transferred from processor to memory or from memory to
processor.
Processor-I/O: Data may be transferred to or from a peripheral device by
transferring between the processor and an I/O module.
Data processing: The processor may perform some arithmetic or logic operation on
data. Control: An instruction may specify that the sequence of execution be altered
Example:
➢ The processor contains a single data register, called the accumulator (AC).
➢ The instruction format provides 4 bits for the opcode, allowing as many as 24 = 16 different
opcodes.
➢ The opcode defines the operation the processor is to perform. The remaining 12 bits of the
instruction can be directly addressed.
➢ The program fragment adds the contents of the memory word at address 940 to the
contents of the memory word at address 941 and stores the result in the location 941.
1. The PC contains 300, the address of the first instruction. This instruction (the value 1940 in
hexadecimal) is loaded into the IR and the PC is incremented.
2. The first 4 bits (first hexadecimal digit) in the IR indicate that the AC is to be loaded from
memory. The remaining 12 bits (three hexadecimal digits) specify the address, which is 940.
3. The next instruction (5941) is fetched from location 301 and the PC is incremented.
4. The old contents of the AC and the contents of location 941 are added and the result is
stored in the AC.
5. The next instruction (2941) is fetched from location 302 and the PC is incremented.
6. The contents of the AC are stored in location 941.
I/O Function:
➢ Data can be exchanged directly between an I/O module and the processor.
➢ Just as the processor can initiate a read or write with memory, specifying the address of a
memory location, the processor can also read data from or write data to an I/O module.
➢ The processor identifies a specific device that is controlled by a particular I/O module. In
some cases, it is desirable to allow I/O exchanges to occur directly with main memory to
relieve the processor of the I/O task.
➢ In such a case, the processor grants to an I/O module the authority to read from or write to
memory, so that the I/O memory transfer can occur without tying up the processor.
➢ During such a transfer, the I/O module issues read or write commands to memory,
relieving the processor of responsibility for the exchange. This operation is known as direct
memory access
1.1.3 Interrupts
➢ An interrupt is defined as hardware or software generated event external to the currently
executing process that affects the normal flow of the instruction execution.
➢ Interrupts are provided primarily as a way to improve processor utilization
Classes of Interrupts:
Program Generated by some condition that occurs as a result of an instruction execution, such
as arithmetic overflow, division by zero, attempt to execute an illegal machine
instruction, and reference outside a user’s allowed memory space.
Timer Generated by a timer within the processor. This allows the operating system to
perform certain functions on a regular basis.
I/O Generated by an I/O controller, to signal normal completion of an operation or to
signal a variety of error conditions.
Hardware failure Generated by a failure, such as power failure or memory parity error.
➢ Let us consider a system with three I/O devices. A printer, a disk, and a
communications line, with increasing priorities of 2, 4, and 5, respectively. A user
program begins at t=0. At t=10, a printer interrupt occurs.
➢ While this routine is still executing, at t=15, a communications interrupts occur.
Because the communications line has highest priority than the printer, the
interrupt request is honored.
➢ The printer ISR is interrupted, its state is pushed onto the stack and the execution
continues at the communications ISR. While this routine is executing an interrupt
occurs at t=20.This interrupt is of lower priority it is simply held and the
communications ISR runs to the completion.
When the communications ISR is complete at t=25, the previous processor state is restored which
the execution of the printer ISR. However, before even a single instruction in that routine can be
executed the processor honors the higher priority disk interrupt and transfers control to the disk
ISR. Only when that routine completes (t= 35) the printer ISR is resumed. When the Printer ISR
completes at t=40then finally the control returns to the user program.
Multiprogramming:
➢ With the use of interrupts, a processor may not be used very efficiently. If the time required
to complete an I/O operation is much greater than the user code between I/O calls then the
processor will be idle much of the time.
➢ A solution to this problem is to allow multiple user programs to be active at the same time.
This approach is called as multiprogramming.
➢ When a program has been interrupted, the control transfers to an interrupt handler, once
the interrupt- handler routine has completed, control may not necessarily immediately be
returned to the user program that was in execution at the time.
➢ Instead, control may pass to some other pending program with a higher priority. This
concept of multiple programs taking turns in execution is known as multiprogramming.
1.1.4 Memory Hierarchy
➢ To achieve greatest performance, the memory must be able to keep up with the processor.
➢ As the processor is executing instructions, we would not want it to have to pause waiting
for instructions or operands.
➢ Thus the cost of memory must be reasonable in relationship to other components.
➢ There is a tradeoff among the three key characteristics of memory: namely, capacity, access
time, and cost.
• Faster access time, greater cost per bit
• Greater capacity, smaller cost per bit
• Greater capacity, slower access speed
The designer would like to use memory technologies that provide for large-capacity
memory. However, to meet performance requirements, the designer needs to use
expensive, relatively lower-capacity memories with fast access times.
➢ The idea is to not rely on a single memory component but to employ a memory hierarchy.
As one goes down the hierarchy, the following occur:
a. Decreasing cost per bit
b. Increasing capacity
c. Increasing access time
d. Decreasing frequency of access to the memory by the processor
➢ The processor is responsible for extracting data from main memory for output and storing
data in main memory for input.
Thus, the instruction set includes I/O instructions in the following categories:
• Control: Used to activate an external device and tell it what to do.
• Status: Used to test various status conditions associated with an I/O module and its
peripherals.
• Transfer: Used to read and/or write data between processor registers and external devices.
Interrupt-Driven I/O:
An alternative to Programmed I/O is for the processor to issue an I/O command to a module and
then go on to do some other useful work.
➢ The processor issues a READ command. The I/O module receives a READ command from
the processor and then proceeds to read data in from the device.
➢ Once the data are in the I/O module’s data register, the module signals an interrupt to the
processor over a control line.
➢ When the interrupt from the I/O module occurs, the processor saves the context of the
program it is currently executing and begins to execute an interrupt-handling program that
processes the interrupt.
➢ Interrupt-driven I/O is more efficient than programmed I/O because it eliminates needless
waiting.
DIRECT MEMORY ACCESS
➢ Interrupt-driven I/O, though more efficient than simple programmed I/O, still requires the
active intervention of the processor to transfer data between memory and an I/O module.
➢ When large volumes of data are to be moved, a more efficient technique is required: direct
memory access (DMA).
➢ The DMA function can be performed by a separate module on the system bus or it can be
incorporated into an I/O module.
✓ When the processor wishes to read or write a block of data, it issues a command to the
DMA module, by sending to the DMA module the following information:
❖ Whether a read or write is requested
❖ The address of the I/O device involved
❖ The starting location in memory to read data from or write data to
❖ The number of words to be read or written
✓ The processor then continues with other work. It has delegated this I/O operation to the
DMA module, and that module will take care of it.
✓ The DMA module transfers the entire block of data, one word at a time, directly to or from
memory without going through the processor. When the transfer is complete, the DMA
module sends an interrupt signal to the processor.
✓ Thus the processor is involved only at the beginning and end of the transfer
MULTICORE ORGANIZATION:
❖ A multi-core processor is an integrated circuit (IC) to which two or more processors
have been attached for enhanced performance, reduced power consumption, and
more efficient simultaneous processing of multiple tasks, it is a growing industry trend
as single-core processors rapidly reach the physical limits of possible complexity and
speed. A basic block diagram of a generic multi-core processor.
❖ An example of a multicore system is the Intel Core i7, which includes four x86
processors, each with a dedicated L2 cache, and with a shared L3 cache
ISSUES IN DEVELOPING MULTI-CORE PROCESSORS MACHINES :
• The first issue is the communication between core processors and the main memory in a
multicore processors' environment.
• This is done either by the use of a single communication bus “shared memory model” or an
interconnection network “distributed memory model” as shown in Figure 5.
• The single bus approach has an upper limit of 32 cores, after that the bus will be overfilled
with transactions that lower the performance of the system [3]
• Since every core processor has its own memory in the distributed memory model, a copy of
the data might not be always the most updated version, which will result in a cache
coherence problem.
• For example, if we have a dual core processor, each core will get a portion of the memory, if
the first core writes a new value for a parameter and the second core had to read the value
of this parameter it will read its own value unless there is a coherence policy.
• Reading a non consistent value of this parameter may result in a program crash. There are
two schemes that forces cache coherence, the snooping protocol and a directory protocol.
The snooping protocol is designed only for a bus based system, it uses a number of states to
determine whether or not there is a need to update the cache entries or not and also if it
has control over writing to the block. However, the directory protocol has the scalability to
work on any arbitrary network. A directory is used to hold information about which of the
memory locations are being used exclusively by one core, and which are shared among
multiple cores
• The second issue that rise in order to fully utilize the multi-core processor technology is
parallelism, programs should have the characteristic of being executed in a parallel order.
• There are three types of parallelism: Instruction level parallelism, thread level parallelism,
and data level parallelism. In the case of Instruction level parallelism, the execution of the
instructions could be done in a parallel way as well as in a sequential way. In the case of
thread level parallelism, multiple threads of the same task are presented to the processor
to be executed simultaneously as shown in Figure 6. In the case of data level parallelism,
common data is being shared among executing processes through memory coherence,
which will improve performance by reducing the time required to load and access memory.
• Starvation is a problem that could occur if the program isn't designed in a parallel way, this
is because one or more cores might starve for data. For example, if a single-threaded
application is to be run in a multi-core processor machine
• The third issue that rise in the development of multi-core processors is power dissipation. If
we allocate two cores on the same chip size a large amount of heat will be generated unless
there is a power control mechanism that shuts down the unused core or limits its power
consumption
In Multiprogramming we will have OS and more user programs. When one job
needs to wait for I/O, the processor can switch to the other job, which is likely
not waiting for I/O.This approach is known as multiprogramming, or
multitasking.
The most notable feature that is useful for multiprogramming is the hardware that
supports I/O interrupts and DMA (direct memory access).
With interrupt-driven I/O or DMA, the processor can issue an I/O command for one job
and proceed with the execution of another job while the I/O is carried out by the device
controller.
When the I/O operation is complete, the processor is interrupted and control is passed
to an interrupt-handling program in the OS.The OS will then passes control to another
job.
Multiprogramming operating systems are fairly sophisticated compared to single-
program, or uniprogramming, systems. To have several jobs ready to run, they must be
kept in main memory, requiring some form of memory management.
In addition, if several jobs are ready to run, the processor must decide which one to run,
this decision requires an algorithm for scheduling.
Time-Sharing Systems:
In time sharing systems the processor time is shared among multiple users.
In a time-sharing system, multiple users simultaneously access the
system through terminals, with the OS interleaving the execution of each
user program in a short burst or quantum of computation.
If there are n users actively requesting service at one time, each user will
only see on the average 1/n of the effective computer capacity.
One of the first time-sharing operating systems to be developed was the
Compatible Time-Sharing System (CTSS)
The system ran on a computer with 32,000 36-bit words of main memory, with
the resident monitor consuming 5000 of that. When control was to be
assigned to an interactive user, the user’s program and data were loaded into
the remaining 27,000 words of main memory.
A program was always loaded to start at the location of the 5000th word
A system clock generated interrupts at a rate of approximately one every 0.2 seconds.
At each clock interrupt, the OS regained control and could assign the processor
to another user. This technique is known as time slicing.
Example: Assume that there are four interactive users with the following memory
requirements, in words: JOB1: 15,000
JOB2: 20,000
JOB3: 5000
JOB4: 10,000
Layered approach:
A system can be made modular in many ways. One method is the layered approach, in
which the operating system is broken into a number of layers (levels). The bottom
layer (layer 0) is the hardware; the highest (layer
N) is the user interface.
Modules:
The best current methodology for operating-system design involves using loadable
kernel modules
The kernel has a set of core components and links in additional services via modules,
either at boot time or during run time.
The kernel provides core services while other services are implemented dynamically, as
the kernel is running.
Linking services dynamically is more comfortable than adding new features directly to
the kernel, which would require recompiling the kernel every time a change was made.
Example: Solaris OS
The Solaris operating system structure is organized around a core kernel with seven types of
loadable kernel modules:
❖ Scheduling classes
❖ File systems
❖ Loadable system calls
❖ Executable formats
❖ STREAMS modules
❖ Miscellaneous
❖ Device and bus drivers
Hybrid Systems:
❖ The Operating System combines different structures, resulting in hybrid systems that
address performance, security, and usability issues.
❖ They are monolithic, because having the operating system in a single address space
provides very efficient performance.
However, they are also modular, so that new functionality can be dynamically added to
thekernel. Example: Linux and Solaris are monolithic (simple) and also modular, IOS.
1.3.2 OPERATING SYSTEM OPERATIONS:
❖ The operating system and the users share the hardware and software resources of the
computer system, so we need to make sure that an error in a user program could cause
problems only for the one programrunning.
❖ Without protection against these sorts of errors, either one erroneous program might
modify another program, the data of another program, or even the operating system
itself.
Dual-Mode and Multimode Operation:
❖ In order to ensure the proper execution of the operating system, we must be able to
distinguish between the execution of operating-system code and user defined code.
❖ The computer systems provide hardware support that allows us to differentiate among
various modes of execution.
There are two separate modes of operation
❖ User mode
❖ Kernel mode(Supervisor mode or 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)
❖ The mode bit, can distinguish between a task that is executed on behalf of the operating
system and one that is executed on behalf of the user.
❖ When the computer system is executing on behalf of a user application, the system is in
user mode and when a user application requests a service from the operating system
the system must make a transition from user to kernel mode
❖ At system boot time, the hardware starts in kernel mode. The operating system is then
loaded and starts user applications in user mode.
❖ Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel
mode (that is, changes the state of the mode bit to 0).
❖ The dual mode of operation provides us with the means for protecting the operating
system from errant users— and errant users from one another
❖ The hardware allows privileged instructions to be executed only in kernel mode. If an
attempt is made to execute a privileged instruction in user mode, the hardware does not
execute the instruction but rather treats it as illegal and traps it to the operating system
❖ System calls provide the means for a user program to ask the operating system to
perform tasks reserved for the operating system on the user program’s behalf.
❖ The lack of a hardware-supported dual mode can cause serious shortcomings in an
operating system.MS-DOS was written for the Intel 8088 architecture, which has no mode
bit and therefore no dual mode
❖ Once hardware protection is in place, it detects errors that violate modes. These errors
are normally handled by the operating system.
Timer:
❖ The operating system maintains control over the CPU. We cannot allow a user program
to get stuck in an infinite loop or to fail to call system services and never return control to
the operating system.
❖ A timer can be set to interrupt the computer after a specified period. A variable timer is
generally implemented by a fixed-rate clock and a counter.
❖ The operating system sets the counter. Every time the clock ticks, the counter is
decremented. When the counter reaches 0, an interrupt occurs
Example: System calls for writing a simple program to read data from one file and copy them
to another file
➢ The caller of the system call need know nothing about how the system call is
implemented or what it does during execution.
➢ The caller need only obey the API and understand what the operating system will do as a
result of the execution of that system call.
Three general methods are used to pass parameters to the operating system
If we create a new job or process, or perhaps even a set of jobs or processes, we should
be able to control its execution that requires to determine and reset the attributes of a
job or process, including the job’s priority, its maximum allowable execution time, and
so on (get process attributes() and set process attributes()).
We may also want to terminate a job or process that we created (terminate process()) if
we find that it is incorrect or is no longer needed.
The System calls associated with process control includes
end, abort
load, execute
create process, terminate process
get process attributes, set process attributes
Wait for time
wait event, signal event
allocate and free memory
When a process has been created We may want to wait for a certain amount of time to
pass (wait time()) or we will want to wait for a specific event to occur (wait event()).
The jobs or processes should then signal when that event has occurred (signal event()
To start a new process, the shell executes a fork() system call. Then, the selected
program is loaded into memory via an exec() system call, and the program is executed
When the process is done, it executes an exit() system call to terminate, returning to the
invoking process a status code of 0 or a nonzero error code.
FILE MANAGEMENT:
In order to work with files We first need to be able to create () and delete () files. Either
system call requires the name of the file and perhaps some of the file’s attributes. Once
the file is created, we need to open() it and to use it.
We may also read (), write (), or reposition ().Finally, we need to close () the file,
indicating that we are no longer using it.
In addition, for either files or directories, we need to be able to determine the values of
various attributes and perhaps to reset them if necessary.
File attributes include the file name, file type, protection codes, accounting information,
and so on. At least two system calls, get file attributes () and set file attributes (), are
required for this function.
The System calls associated with File management includes
File management
create file, delete file
open, close
read, write, reposition
get file attributes, set file attributes
DEVICE MANAGEMENT:
A process may need several resources to execute—main memory, disk drives, access
to files, and so on. If the resources are available, they can be granted, and control can
be returned to the user process. Otherwise, the process will have to wait until
sufficient resources are available.
A system with multiple users may require us to first request() a device, to ensure
exclusive use of it.
After we are finished with the device, we release() it. These functions are similar to the
open() and close() system calls for files.
Once the device has been requested (and allocated to us), we can read(), write(), and
(possibly) reposition() the device, just as we can with files.
I/O devices are identified by special file names, directory placement, or file attributes.
The System calls associated with Device management includes
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
INFORMATION MAINTENANCE:
Many system calls exist simply for the purpose of transferring information between the
user program and the operating system.
Example, most systems have a system call to return the current time() and date().
Other system calls may return information about the system, such as the number of
current users, the version number of the operating system, the amount of free memory
or disk space, and so on.
Many systems provide system calls to dump() memory. This provision is useful for
debugging.
Many operating systems provide a time profile of a program to indicate the amount of
time that the program executes at a particular location or set of locations.
The operating system keeps information about all its processes, and system calls are
used to access this information.
Generally, calls are also used to reset the process information (get process attributes()
and set process attributes()).
The System calls associated with Device management includes
get time or date, set time or date
get system data, set system data
get process, file, or device attributes
set process, file, or device attributes
COMMUNICATION:
There are two common models of Interprocess communication: the message passing
model and the shared- memory model.
In the message-passing model, the communicating processes exchange messages with
one another to transfer information.
Messages can be exchanged between the processes either directly or indirectly through
a common mailbox.
Each process has a process name, and this name is translated into an identifier by which
the operating system can refer to the process. The get hostid() and get processid()
system calls do this translation.
The recipient process usually must give its permission for communication to take place
with an accept connection () call.
The source of the communication, known as the client, and the receiving daemon,
known as a server, then exchange messages by using read message() and write
message() system calls.
The close connection() call terminates the communication
In the shared-memory model, processes use shared memory create() and shared
memory attach() system calls to create and gain access to regions of memory owned by
other processes.
The system calls associated with communication includes,
create, delete communication connection
send, receive messages
Transfer status information
attach or detach remote devices
PROTECTION:
Protection provides a mechanism for controlling access to the resources provided by a
computer system.
System calls providing protection include set permission () and get permission (), which
manipulate the permission settings of resources such as files and disks.
The allow user () and deny user () system calls specify whether particular users can—or
cannot—be allowed access to certain resources
1.5 System Programs
System programs, also known as system utilities, provide a convenient environment for
program development and execution.
They can be divided into these categories:
File management
Status information
File modification.
Programming-language support
Program loading and execution
Communications
Background services
File Management:These programs create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories.
Status Information: Some programs simply ask the system for the date, time, amount of
available memory or disk space, number of users, or similar status information.
Others are more complex, providing detailed performance, logging, and debugging
information.
File Modification: Several text editors may be available to create and modify the content of
files stored on disk or other storage devices
There may also be special commands to search contents of files or perform transformations
of the text.
Programming Language support: Compilers, assemblers, debuggers, and interpreters for
common programming languages (such as C, C++, Java, and PERL) are often provided with the
operating system.
Program Loading and Execution: Once a program is assembled or compiled, it must be loaded
into memory to be executed.
The system may provide absolute loaders, relocatable loader.
Communication: These programs provide the mechanism for creating virtual connections
among processes, users, and computer systems.
They allow users to send messages to one another’s screens, to browse Web pages, to send e-
mail messages, to log in remotely, or to transfer files from one machine to another.
Background Services: All general-purpose systems have methods for launching certain
system-program processes at boot time. Some of these processes terminate after completing
their tasks, while others continue to run until the system is halted. Constantly running system-
program processes are known as services, subsystems, or daemons.
Along with system programs, most operating systems are supplied with programs that
are useful in solving common problems or performing common operations.
Such application programs include Web browsers, word processors and text
formatters, spreadsheets, database systems, compilers, plotting and statistical-
analysis packages, and games
1.6 OS Generation
The operating systems are designed to run on any of a class of machines at a variety of
sites with a variety of peripheral configurations.
The Computer system must then be configured or generated for each specific computer
site, a process sometimes known as system generation SYSGEN.
The operating system is normally distributed on disk, on CD-ROM or DVD-ROM, or as an
―ISO‖ image, which is a file in the format of a CD-ROM or DVD-ROM.
To generate a system, the special program called SYSGEN program reads from a given
file, or asks the operator of the system for information concerning the specific
configuration of the hardware system.
The following kinds of information must be determined.
❖ What CPU is to be used?
❖ How will the boot disk be formatted?
❖ How much memory is available?
❖ What devices are available?
❖ What operating-system options are desired, or what parameter values are to be
used?
A system administrator can use this information to modify a copy of the source code
of the operating system. The operating system then is completely compiled.
The system description can lead to the creation of tables and the selection of modules
from a precompiled library. These modules are linked together to form the generated
operating system
It is also possible to construct a system that is completely table driven. All the code is
always part of the system, and selection occurs at execution time, rather than at
compile or link time
1.7 System Boot
The procedure of starting a computer by loading the kernel is known as booting the
system.
A small piece of code known as the bootstrap program or bootstrap loader locates the
kernel,loads it into main memory, and starts its execution.
In some computer systems system booting is a two step process.
First a simple bootstrap loader fetches a more complex boot program from disk
A complex boot program loads the OS
The bootstrap program can perform a variety of tasks. Usually, one task is to run
diagnostics to determine the state of the machine.
It can also initialize all aspects of the system, from CPU registers to device controllers
and the contents of main memory and then it starts the Operating system.
All forms of ROM are also known as firmware, since their characteristics fall somewhere
between those of hardware and those of software.
A problem with firmware in general is that executing code there is slower than
executing code in RAM.
Some systems store the operating system in firmware and copy it to RAM for fast
execution.
A final issue with firmware is that it is relatively expensive, so usually only small
amounts are available.
For large operating systems the bootstrap loader is stored in firmware, and the
operating system is on disk.
The Bootstrap program has a piece of code that can read a single block at a fixed
location from disk into memory and execute the code from that Boot block.
The program stored in the boot block may be sophisticated enough to load the entire
operating system into memory and begin its execution.
A disk that has a Boot partition is called as a Boot Disk.
GRUB is an example of an open-source bootstrap program for Linux systems
The kernel is the central module of an operating system.
The kernel remains in the main memory and is not terminated until the system shuts down.
Kernels are categorized as being of four types- monolithic, microkernel, hybrid, and exokernel.
Types of Kernels
1. Monolithic Kernel:
In this, all OS services operate in the kernel space i.e., user services and kernel services are implemented in
the same memory space.
This increases the size of Kernel and OS makes the execution of a process faster.
There are dependencies between system components. It has huge lines of code that make it complex.
Advantages of Monolithic kernel:
Good performance.
Provides CPU scheduling
memory scheduling
file management
2. Micro Kernel:
This type has a minimalist approach along with virtual memory and thread scheduling.
It is stable, has less services in the kernel space and puts rest in user space.
This means that it makes use of both the kernel space and user.
Communication is done through message parsing and that reduces the speed of execution.
More stable.
With the speed and design of a monolithic kernel and the modularity and stability of a microkernel,
Some services like network stack and file systems are run in Kernel space in order to reduce
performance overhead.
5. Nano Kernel:
Due to micro kernels also not having system services, these two have become analogous to each other.
The code of the kernel is very small and the Kernel supports nanosecond clock resolution.
Although two processes may be associated with the same program, they are nevertheless
considered two separate execution sequences.
For instance, several users may be running different copies of the mail program, or the same
user may invoke many copies of the web browser program.
Each of these is a separate process; and although the text sections are equivalent, the data,
heap and stack sections vary
2.1.1.1 Process State:
As a process executes, it changes state.
The state of a process is defined in part by the current activity of that process.
A process may be in one of the following states:
New. The process is being created.
Running. Instructions are being executed.
Waiting. The process is waiting for some event to occur (such as an I/O
completion or reception of a signal)
Ready. The process is waiting to be assigned to a processor.
Terminated. The process has finished execution
Threads
The process model discussed implies that a process is a program that performs a single
thread of execution.
For example, when a process is running a word-processor program, a single thread of
instructions is being executed. This single thread of control allows the process to perform
only one task at a time.
The user cannot simultaneously type in characters and run the spell checker within the
same process.
Most modern operating systems have extended the process concept to allow a process to
have multiple threads of execution and thus to perform more than one task at a time.
This feature is especially beneficial on multicore systems, where multiple threads can run
in parallel.
On a system that supports threads, the PCB is expanded to include information for each
thread.
A new process is initially put in the ready queue. It waits there until it is selected for
execution, or dispatched.
Once the process is allocated the CPU and is executing, one of several events could occur:
• The process could issue an I/O request and then be placed in an I/O queue.
• The process could create a new child process and wait for the child’s termination.
• The process could be removed forcibly from the CPU, as a result of an interrupt, and be put
back in the ready queue.
2.1.2.2 Schedulers:
For scheduling purposes, the operating system must select processes from the queues in some
approach. The selection process is carried out by the appropriate scheduler.
It makes use of two types of schedulers
o Long term scheduler or job scheduler
o Short term scheduler or CPU scheduler.
o Medium term scheduler
The long-term scheduler, or job scheduler, selects processes from the job queue which is in
the disk and loads them into memory for execution.
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.
The Long term scheduler must have a careful selection of both I/O Bound and CPU Bound
process.
An I/O-bound process is one that spends more of its time doing I/O than it spends doing
computations.
A CPU-bound process, in contrast, generates I/O requests infrequently, using more of its
time doing computations.
If all processes are I/O bound, the ready queue will almost always be empty, If all processes
are CPU bound, the I/O waiting queue will almost always be empty, devices will go unused.
The medium-term scheduler is used to remove a process from memory to reduce the degree
of multiprogramming. Later, the process can be reintroduced into memory, and its execution
can be continued where it left off. This scheme is called swapping.
The process is swapped out, and is later swapped in, by the medium-term scheduler.
Context Switch:
The process of switching the CPU from one process to another process requires performing
a state save of the current process and a state restore of a different process. This task is
known as a context switch.
When an interrupt occurs, the system needs to save the current context of the process
running on the CPU so that it can restore that context when its processing is done.
The context is represented in the PCB of the process. It includes the value of the CPU registers,
the process state and memory management information
When a process creates a child process, that child process will need certain resources (CPU
time, memory, files, I/O devices) to accomplish its task.
A child process may be able to obtain its resources directly from the operating system, or it
may be constrained to a subset of the resources of the parent process.
The parent may have to partition its resources among its children, or it may be able to share
some resources (such as memory or files) among several of its children
When a process creates a new process, two possibilities for execution exist:
1. The parent continues to execute concurrently with its children.
2. The parent waits until some or all of its children have terminated
There are also two address-space possibilities for the new process:
1. The child process is a duplicate of the parent process (it has the same program as the
parent).
2. The child process has a new program loaded into it.
In UNIX Operating System,
A new process is created by the fork() system call. The new process consists of a copy of the
address space of the original process. This mechanism allows the parent process to
communicate easily with its child process.
The return code for the fork() is zero for the new (child) process, whereas the (nonzero)
process identifier of the child is returned to the parent.
After a fork() system call, one of the two processes typically uses the exec() system call to
replace the process’s memory space with a new program.
The exec() system call loads a binary file into memory and starts its execution.
In this manner, the two processes are able to communicate and then go their separate ways.
The parent can then create more children; or, if it has nothing else to do while the child runs,
it can issue a wait() system call to move itself off the ready queue until the termination of the
child
Shared-Memory Systems:
Interprocess communication using shared memory requires communicating processes to
establish a region of shared memory.
Shared-memory region resides in the address space of the process creating the shared-
memory segment.
Other processes that wish to communicate using this shared-memory segment must attach it
to their address space.
They can then exchange information by reading and writing data in the shared areas.
EXAMPLE:PRODUCER – CONSUMER PROCESS:
A producer process produces information that is consumed by a consumer process.
One solution to the producer–consumer problem uses shared memory
To allow producer and consumer processes to run concurrently, we must have available a
buffer of items that can be filled by the producer and emptied by the consumer.
This buffer will reside in a region of memory that is shared by the producer and consumer
processes. A producer can produce one item while the consumer is consuming another item.
Two types of buffers can be used.
o Bounded Buffer.
o Unbounded Buffer.
The unbounded buffer places no practical limit on the size of the buffer. The consumer may
have to wait for new items, but the producer can always produce new items.
The bounded buffer assumes a fixed buffer size. In this case, the consumer must wait if the
buffer is empty, and the producer must wait if the buffer is full.
The following variables reside in a region of memory shared by the producer and consumer
processes:
#define BUFFER SIZE 10
typedef struct {
...
}item;
item buffer[BUFFER SIZE];
int in = 0;
int out = 0;
The variable in points to the next free position in the buffer; out points to the first full
position in the buffer. The buffer is empty when in = = out; the buffer is full when ((in + 1)
% BUFFER SIZE) == out.
CODE FOR PRODUCER PROCESS:
item next_produced;
while (true) {
/* produce an item in next_produced */
while ((in + 1) % BUFFER SIZE) = = out)
; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER SIZE;
}
The producer process has local variable next_produced in which the new item to be
produced is stored.
The consumer process has a local variable next_consumed in which the item to be consumed
is stored.
This scheme allows at most BUFFER_SIZE − 1 items in the buffer at the same time.
CODE FOR CONSUMER PROCESS
item next_consumed;
while (true) {
while (in = = out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
/* consume the item in next_consumed */
}
Message-Passing Systems:
Message passing provides a mechanism to allow processes to communicate and to
synchronize their actions without sharing the same address space
A message-passing facility provides at least two operations:
o send(message)
o receive(message)
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 send()/receive()
operations:
o Direct or indirect communication
o Synchronous or asynchronous communication
o Automatic or explicit buffering
Naming : Processes that want to communicate must have a way to refer to each other. They can use
either direct or indirect communication
Direct Communication:
Each process that wants to communicate must explicitly name the recipient or sender of the
communication.
Direct communication can be done in two ways symmetric addressing and asymmetric
addressing.
In Symmetric addressing both the sender process and the receiver process must name the
other to communicate.
o send(P, message)—Send a message to process P.
o receive(Q, message)—Receive a message from process Q.
In Asymmetric addressing only the sender names the recipient; the recipient is not required to
name the sender.
o send(P, message)—Send a message to process P.
o receive(id, message)—Receive a message from any process . The variable id is set to
the name of the process with which communication has taken place
A communication link in this scheme has the following properties:
• A link is established automatically between every pair of processes that want to
communicate. The processes need to know only each other’s identity to communicate.
• A link is associated with exactly two processes.
• Between each pair of processes, there exists exactly one link.
Disadvantage:
The disadvantage in both of these schemes (symmetric and asymmetric) is the limited modularity of
the resulting process definitions. Changing the identifier of a process may necessitate examining all
other process definitions.
Hard-coding techniques, where identifiers must be explicitly stated, are less desirable than
techniques involving indirection, as described next.
Indirect communication:
With indirect communication, the messages are sent to and received from mailboxes, or
ports.
A mailbox can be viewed abstractly as an object into which messages can be placed by
processes and from which messages can be removed. Each mailbox has a unique
identification.
A process can communicate with another process via a number of different mailboxes, but
two processes can communicate only if they have a shared mailbox.
The send() and receive() primitives are defined as follows:
o send(A, message)—Send a message to mailbox A.
o receive(A, message)—Receive a message from mailbox A.
In this scheme, a communication link has the following properties:
• A link is established between a pair of processes only if both members of the pair have a
shared mailbox.
• A link may be associated with more than two processes.
• Between each pair of communicating processes, a number of different links may exist, with
each link corresponding to one mailbox.
Now suppose that processes P1, P2, and P3 all share mailbox A. Process P1 sends a message
to A, while both P2 and P3 execute a receive() from A. Which process will receive the
message sent by P1? The answer depends on which of the following methods we choose:
o Allow a link to be associated with two processes at most.
o Allow at most one process at a time to execute a receive() operation.
o Allow the system to select arbitrarily which process will receive the message (that is,
either P2 or P3, but not both, will receive the message). The system may define an
algorithm for selecting which process will receive the message (for example, round
robin, where processes take turns receiving messages). The system may identify the
receiver to the sender.
A mailbox may be owned either by a process or by the operating system.
Synchronous or asynchronous communication
Communication between processes takes place through calls to send() and receive()
primitives.
Message passing may be either blocking or nonblocking— also known as synchronous and
asynchronous
Blocking send. The sending process is blocked until the message is received by the receiving
process or by the mailbox
Nonblocking send. The sending process sends the message and resumes Operation
Blocking receive. The receiver blocks until a message is available.
Nonblocking receive. The receiver retrieves either a valid message or a null.
When both send() and receive() are blocking, we have a rendezvous between the sender and
the receiver.
When both send() and receive() are blocking, we have a rendezvous(meeting) between the
sender and the receiver
Automatic or explicit buffering:
Messages exchanged by communicating processes reside in a temporary queue. Basically,
such queues can be implemented in three ways:
o Zero capacity.
o Bounded capacity
o unbounded capacity
Zero capacity. The queue has a maximum length of zero (the link cannot have any messages
waiting in it). In this case, the sender must block until the recipient receives the message.
Bounded capacity. The queue has finite length n; thus, at most n messages can reside in it.
Unbounded capacity. The queue’s length is potentially infinite; thus, any number of
messages can wait in it. The sender never blocks.
The zero-capacity case is sometimes referred to as a message system with no buffering. The
other cases are referred to as systems with automatic buffering.