ECT426 Real Time Operating Systems
ECT426 Real Time Operating Systems
MODULE 1
Introduction to Operating system
• The kernel is the software that contains the operating system’s core
components.
History
The objectives:
• 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.
• These utilities, or library programs, frequently used functions that assist in program
creation, the management of files, and the control of I/O devices.
and the application, while it is running, will invoke the utilities to perform
certain functions.
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.
• The sole aim of the kernel is to manage the communication between the
software (user level applications) and the hardware (CPU, disk memory etc).
• 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.
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.
1. A program in execution
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
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:
• 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
• 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 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 :
• Processes that are not running must be kept in some sort of queue, waiting their turn to
execute and there is a single queue.
• 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
• 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.
• 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:
• For example, if a new user attempts to log on to a time-sharing system or a new batch
job is submitted
• 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.
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
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.
• 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
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.