0% found this document useful (0 votes)
19 views64 pages

ECT426 Real Time Operating Systems

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views64 pages

ECT426 Real Time Operating Systems

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

ECT426

REAL TIME OPERATING


SYSTEMS

MODULE 1
Introduction to Operating system

• An OS is a program that controls the execution of application programs


and acts as an interface between applications and the computer hardware.
• It enables applications to interact with a computer’s hardware.
Through a designated application programme interface, the application
programmes request services from the operating system (API).

• The kernel is the software that contains the operating system’s core
components.
History
The objectives:

• Convenience: An OS makes a computer more convenient to use.

• Efficiency: An OS allows the computer system resources to be used in


an efficient manner.

• Ability to evolve: An OS should be constructed in such a way as to


permit the effective development, testing, and introduction of new
system functions without interfering with service.
The Operating System as a User/Computer Interface

• The hardware and software used in providing applications to a user can be


viewed in a layered or hierarchical fashion

• The user of those applications, the end user, generally is not concerned with the
details of computer hardware. Thus, the end user views a computer system in
terms of a set of applications.

• An application can be expressed in a programming language and is developed


by an application programmer.
• It is difficult to develop an application program as a set of machine instructions that is
completely responsible for controlling the computer hardware.

• So, a set of system programs is provided, referred as utilities, or library programs.

• These utilities, or library programs, frequently used functions that assist in program
creation, the management of files, and the control of I/O devices.

• A programmer will make use of these facilities in developing an application,

and the application, while it is running, will invoke the utilities to perform

certain functions.

• The most important collection of system programs comprises the OS


• The OS masks the details of the hardware from the programmer and
provides the programmer with a convenient interface for using the
system.

• It acts as mediator, making it easier for the programmer and for


application programs to access and use those facilities and services.
Functions of Operating System

Function
Error Detection operating system checks the system for any external threat or malicious
software activity. It also checks the hardware for any type of damage. This
process displays several alerts to the user so that the appropriate action can
be taken against any damage caused to the system.
Job Scheduling In a multitasking OS where multiple programs run simultaneously, the
operating system determines which applications should run in which order
and how time should be allocated to each application.
Kernel
• A kernel is a central component of an operating system.

• It acts as an interface between the user applications and the hardware.

• The sole aim of the kernel is to manage the communication between the
software (user level applications) and the hardware (CPU, disk memory etc).

• A portion of the OS is in main memory. This includes the kernel , or nucleus ,


which contains the most frequently used functions in the OS and, at a given
time, other portions of the OS currently in use. The remainder of main memory
contains user programs and data
The main tasks of the kernel are :

• Process management
• Device management
• Memory management
• Interrupt handling
• I/O communication
• File system.
• Kernel as described above is the heart of OS which manages the core
features of an OS

• If some useful applications and utilities are added over the kernel, then
the complete package becomes an OS.

• So, it can easily be said that an operating system consists of a kernel


space and a user space.
Types Of Kernels -Assignment

1. Monolithic -
2. Micro Kernel
• It is inefficient for applications to be written directly for a given hardware platform.
• The principal reasons for this are as follows:
• Numerous applications can be developed for the same platform. Thus, it makes
sense to develop common routines for accessing the computer’s resources
• The processor itself provides only limited support for multiprogramming. Software
is needed to manage the sharing of the processor and other resources by multiple
applications at the same time
• When multiple applications are active at the same time, it is necessary to
protect the data, I/O use, and other resource use of each application from
the others
• How OS can, manage the execution of applications so that
1. Resources are made available to multiple applications.

2. The physical processor is switched among multiple applications so all will


appear to be progressing.

3. The processor and I/O devices can be used efficiently.

Approach taken by all modern operating systems is to rely on a model in


which the execution of an application corresponds to the existence of one or more
processes.
• For a program to be executed, a process, or task, is created for that program
Processes and Process Control Blocks
• Term process can be:

1. A program in execution

2. An instance of a program running on a computer

3. The entity that can be assigned to and executed on a processor

4. A unit of activity characterized by the execution of a sequence of instructions,

a current state, and an associated set of system resources


Process is an entity that consists of a number of elements.
Two essential elements of a process are program code (which may be shared with
other processes that are executing the same program) and a set of data associated
with that code.
• Processor begins to execute this program code, and we refer to this executing
entity as a process.
Process Control Block
• Process can be uniquely
characterized by a number
of elements shared and is
stored in a data structure
called Process Control
Block

• Process Control Block


created and managed by
the OS.
Entity / Elements Function

Identifier A unique identifier associated with this process, to distinguish it from all other processes

State Current status of process. Eg: If the process is currently executing, it is in the running state

Priority Priority level relative to other processes.

Program counter The address of the next instruction in the program to be executed

Memory pointers Includes pointers to the program code and data associated with this process, plus any memory blocks
shared with other processes

Context data These are data that are present in registers in the processor while the process is executing

I/O status Includes outstanding I/O requests, I/O devices (e.g., disk drives) assigned to this process, a list of files
information in use by the process, and so on

Accounting Include the amount of processor time and clock time used, time limits, account numbers etc
information
Process control block:

• contains sufficient information so that it is possible to interrupt a running process and


later resume execution as if the interruption had not occurred.

• Is the key tool that enables the OS to support multiple processes and to provide for

multiprocessing

• Process consists of program code and associated data plus a process control
block.

• For a single-processor computer, at any given time, at most one process is executing
and that process is in the running state
PROCESS STATES

• Processor executes instructions from its list in the sequence dictated by the program counter
• Program counter may refer to code in different programs that are part of different processes.

• But for an individual program, its execution involves a sequence of instructions within that
program

• Individual process can be characterized by listing the sequence of instructions that execute for
that process. Such a listing is referred to as a trace of the process.

• Behavior of the processor can be characterized by showing how the traces of the various
processes are interleaved
Example

Assumptions in this example:

• No use of virtual memory; thus all three processes are represented by programs that are fully
loaded

• In main memory OS only allows a process to continue execution for a maximum of six
instruction cycles, after which it is interrupted this prevents any single process from
monopolizing processor time
• Fourth instruction of Process B invokes an I/O operation for which the process must wait.
Example

Dispatcher program that switches the processor from one process to another.
A Two-State Process Model
• Principal responsibility of OS is to control the execution of processes; ie determining the
interleaving pattern for execution and allocating resources to processes.

• The first step in designing an OS to control processes is to describe the behavior that we would
like the processes to exhibit.
• Simplest possible model of a process is that at any time it is either being executed by a
processor or not.
• In this model, a process may be in one of two states: Running or Not Running
A Two-State Process Model
A Two-State Process Model

• When the OS creates a new process, it creates a process control block for the process and

enters that process into the system in the Not Running state.

• The existence of process is known to the OS, and is in queue to execute.

• The currently running process will be interrupted on time basis and the dispatcher portion of
the OS will select some other process to run.

• Once new process is selected, the former process moves from the Running state to the Not
Running state, and one of the other processes moves to the Running state
A Two-State Process Model

• Design elements of the OS used here so that the OS can keep track of it :

current state and location in memory

• Processes that are not running must be kept in some sort of queue, waiting their turn to
execute and there is a single queue.

• Each entry is a pointer to the process control block of a particular process.

• Or the queue may consist of a linked list of data blocks, in which each block represents one
process
A Two-State Process Model - behavior of the dispatcher

• A process that is interrupted by the dispatcher is transferred to the queue of


waiting processes.

• If the process has completed or aborted, it is discarded (exits the system).

• In either case, the dispatcher takes another process from the queue to execute.
The Creation and Termination of Processes - Process Creation

• When a new process is to be added to those currently being managed, the OS builds the data
structures that are used to manage the process and allocates address space in main memory to
the process.
• OS is responsible for the creation of the new pro:
In a batch environment, a process is created in response to the submission of a job.
In an interactive environment, a process is created when a new user attempts to log on.
• OS may also create a process on behalf of an application. Eg: Print a File
• OS creates a process at the explicit request of another process, the action is referred to
as process spawning.

• ie allow one process to cause the creation of another.

• an application process may generate another process to receive data that the application
is generating and to organize those data into a form suitable for later analysis.

• The new process runs in parallel to the original process and is activated from time to
time when new data are available.

• When one process spawns another, the former is referred to as the parent process, and
the spawned process is referred to as the child process.
Process Termination
• A batch job should include a Halt instruction or an explicit OS service call for termination.

• In the former case, the Halt instruction will generate an interrupt to alert the OS that a process
has completed.

• For an interactive application, the action of the user will indicate when the process is
completed.

• Example: In a time-sharing system, the process for a particular user is to be terminated when
the user logs off or turns off his or her terminal.
• On a personal computer or workstation, a user may quit an application (e.g., word processing
or spreadsheet
• A number of error and fault conditions can lead to the termination of a process.
A Five-State Model

• In two state model, some processes in the Not Running state are ready to execute, while
others are blocked, waiting for an I/O operation to complete.

• Thus, using a single queue, the dispatcher could not just select the process at the oldest end of
the queue.

• But, the dispatcher would have to scan the list looking for the process that is not blocked and
that has been in the queue the longest.

• Best solution is to split the Not Running state into two states: Ready and Blocked.
A Five-State Model
Five states are:

Running process that is currently being executed


Ready process that is prepared to execute when given the opportunity.
Blocked/Waiting A process that cannot execute until some event occurs, such as the
completion of an I/O operation
New A process that has just been created but has not yet been admitted to the
pool of executable processes by the OS. Eg: Attempt to log in
Exit A process that has been released from the pool of executable processes
by the OS, either because it halted or because it aborted for some reason.
• The New state corresponds to a process that has just been defined.

• For example, if a new user attempts to log on to a time-sharing system or a new batch
job is submitted

• To define OS, a new process in two stages

• First, the OS creates an identifier associated with the process. Any tables that will be
needed to manage the process are allocated and built.

• At this point, the process is in the New state. ie the OS has performed the necessary
actions to create the process but has not committed itself to the execution of the process.

• While a process is in the new state, information concerning the process that is needed by
the OS is maintained in control tables in main memory;
• While the process is in the New state, the program remains in secondary storage,
typically disk storage and not in main memory, and no space has been allocated
for the data associated with that program.
• A process exits a system

• First, a process is terminated when it reaches a natural completion point / when it aborts due to
an unrecoverable error /when another process with the appropriate authority causes the process
to abort, moving the process to the exit state

• The tables and other information associated with the job are temporarily preserved by the OS,
which provides time for auxiliary or support programs to extract any needed information

• Example: An accounting program may need to record the processor time and other resources
utilized by the process for billing purposes.

• Once these programs have extracted the needed information, the OS no longer needs to maintain
any data relating to the process and the process is deleted from the system.
Transitions in 5 state model
Null: New A new process is created to execute a program

New : Ready This transition take place when OS it is ready to take on an additional process. Most
systems set some limit based on the number of existing processes or the amount of virtual
memory committed to existing processes. This limit assures that there are not so many
active processes as to degrade performance

Ready : When it is time to select a process to run, the OS chooses one of the processes in the
Running Ready state. This is the job of the scheduler or dispatcher.

Running : Process release processor when :


Ready Running process has reached the maximum allowable time for uninterrupted execution /
Higher priority process ready for execution / a process may voluntarily release control of
the processor (Eg: A background process that performs some accounting or maintenance
function periodically.)

Another process comes to running stage. First process is now called preempted process
Running: Blocked Process is put in the Blocked state if it requests something for which it must wait.
Eg: It can request a resource, such as a file or a shared section of virtual memory,
that is not immediately available. I/O facility

When processes communicate with each other, a process may be blocked


when it is waiting for another process to provide data or waiting for a message
from another process.

Blocked: Ready process in the Blocked state is moved to the Ready state when the event for which it
has been waiting occurs

Ready : Exit A parent may terminate a child’ process at any time. Also, if a parent terminates, all
child processes associated with that parent may be terminated

Blocked: Exit
Running: Exit The currently running process is terminated by the OS if the process indicates
that it has completed, or if it aborts
Queueing discipline two queues: a Ready queue and a Blocked queue
Suspended Processes
• Three principal states (Ready, Running, Blocked) provide a systematic way of modeling the behavior of
processes

• In a system that does not employ virtual memory, each process to be executed must be loaded fully into
main memory. ie all of the processes in all of the queues must be residing in main memory.

• I/O activities are much slower than computation and therefore the processor in a uniprogramming system
is idle most of the time.

• Memory holds multiple processes and the processor can move to another process when one process is
blocked. But the processor is so much faster than I/O and it could be possible that most of the processes
in memory is waiting for I/O.

• Thus, even with multiprogramming, a processor could be idle most of the time.
• Main memory could be expanded to accommodate more processes. But,

• First, there is a cost associated with main memory, which, though small on a per-
byte basis, begins to add up as we get into the gigabytes of storage.

• Second, the appetite of programs for memory has grown as fast as the cost of
memory has dropped. So larger memory results in larger processes, not more
processes.
Swapping
• Moves part or all of a process from main memory to disk.

• When none of the processes in main memory is in the Ready state, the OS swaps one of the
blocked processes out on to disk into a suspend queue.

• This is a queue of existing processes that have been temporarily kicked out of main memory, or
suspended.

• The OS then brings in another process from the suspend queue, or it honors a new-process
request.

• Execution then continues with the newly arrived process.


• Swapping, is an I/O operation, is generally the fastest I/O on a system (e.g., compared to tape
or printer I/O), swapping will usually enhance performance.

• Use of swapping adds one other state to our process behavior model : the Suspend state.

• When all of the processes in main memory are in the Blocked state, the OS can suspend one
process by putting it in the Suspend state and transferring it to disk.

• The space that is freed in main memory can then be used to bring in another process.
• When the OS has performed a swapping-out operation, it has two choices for selecting a
process to bring into main memory: It can admit a newly created process or it can bring in a
previously suspended process.

• All of the processes that have been suspended were in the Blocked state at the time of
suspension. It would not be helpful to bring a blocked process back into main memory, as it is
still not ready for execution.

• Each process in the Suspend state was originally blocked on a particular event. When that
event occurs, the process is not blocked and is potentially available for execution.

• There are two independent concepts here: whether a process is waiting on an event (blocked
or not) and whether a process has been swapped out of main memory
Ready: The process is in main memory and available for execution
Blocked: The process is in main memory and awaiting an event.
Blocked/Sus The process is in secondary memory and awaiting an event
pend:
Ready/Suspe The process is in secondary memory but is available for
nd execution as soon as it is loaded into main memory
The dashed lines in the figure indicate possible but not
necessary transitions.
Blocked : Blocked/Suspend If there are no ready processes, then at least one blocked process is swapped
out to make room for another process that is not blocked.
This transition can be made even if there are ready processes available, if the
OS determines that the currently running process or a ready process that it
would like to dispatch requires more main memory to maintain adequate
performance

Blocked/Suspend : A process in the Blocked/Suspend state is moved to the Ready/Suspend state


Ready/Suspend
when the event for which it has been waiting occurs.
Ready/Suspend : Ready When there are no ready processes in main memory, the OS will need
to bring one in to continue execution.
Also, if a process in the Ready/Suspend state has higher priority than
any of the processes in the Ready state, the OS give more important to
get at the higher-priority process

Ready : Ready/Suspend OS would prefer to suspend a blocked process rather than a ready one,
because the ready process can now be executed, whereas the blocked
process is taking up main memory space and cannot be executed.
However, it may be necessary to suspend a ready process if that is the
only way to free up a sufficiently large block of main memory.
Also, the OS may choose to suspend a lower–priority ready process
rather than a higher–priority blocked process if it believes that the
blocked process will be ready soon.
New : Ready/Suspend When a new process is created, it can either be added to the Ready queue or the
and New : Ready Ready/Suspend queue. The OS must create a process control block and allocate an address
space to the process. OS prefer to do this duties at an early time, so that it can maintain a
large pool of processes that are not blocked.
As, there would often be insufficient room in main memory for a new process; hence the
use of the (New : Ready/Suspend) transition.

Blocked/Suspend: Blocked process is not ready to execute and is not already in main memory, what is the point of
bringing it in? But consider the following scenario: A process terminates, freeing up some
main memory. There is a process in the (Blocked/Suspend) queue with a higher priority
than any of the processes in the (Ready/Suspend) queue and the OS has reason to believe
that the blocking event for that process will occur soon. Under these circumstances,
it would seem reasonable to bring a blocked process into main memory in preference to a
ready process.
Running : Ready/Suspend a running process is moved to the Ready state when its time allocation expires. If, the OS is
preempting the process because a higher-priority process on the Blocked/Suspend
queue has just become unblocked, the OS could move the running process
directly to the (Ready/Suspend) queue and free some main memory.

Any State : Exit:

You might also like