UNIT IV - Real Time Operating System
UNIT IV - Real Time Operating System
(RTOS)
RTOS
Why we go for RTOS
Requirements for RTOS
RTOS
• A real time operating system (RTOS) is
multitasking operation system for the
applications with hard or soft real time
constraints
• RTOS is an OS for response time controlled
and event controlled process
REAL TIME SYSTEM
• A system is said to be Real Time if it is
required to complete it’s work & deliver it’s
services on time.
• Example – Flight Control System
– All tasks in that system must execute on
time.
GPOS Vs RTOS
• A GPOS is used for systems/applications that are not
time critical.
• In the case of a GPOS – task scheduling is not based on
“priority”,it is programmed to achieve high throughput
• A GPOS is made for high end, general purpose systems
whereas RTOS is usually designed for a low end, stand
alone device
• All the process and threads in RTOS has got bounded
latencies – which means –a process/thread will get
executed within a specified time limit.
Classification real time systems(RTS)
Memory management
Multitasking
Task Management
Time Management
Context switching
Scheduling
Semaphore
Inter Task Communication
Interrupt Handling
Interrupt Handling
Tasks, Process and Threads
• Task – something that needs to be done (job)
• It is defined as the program in execution and
the related information maintained by the OS
for the program
• Process: A program or part of it in execution
Process
• A process is a program, or part of it in
execution.
• A process requires various system resources
like CPU for execution, memory for storing the
code, I/O devices for information exchange.
Process
Stack Pointer
Working Registers
Process
Status Registers
Code Memory
Program Counter corresponding to
the process
Period of a process is the time between successive executions
Process State
S.N. Process State & Description
1 Start
This is the initial state when a process is first started/created.
2 Ready
The process is waiting to be assigned to a processor. Ready processes are
waiting to have the processor allocated to them by the operating system so
that they can run. Process may come into this state after Start state or while
running it by but interrupted by the scheduler to assign CPU to some other
process.
3 Running
Once the process has been assigned to a processor by the OS scheduler, the
process state is set to running and the processor executes its instructions.
4 Waiting
Process moves into the waiting state if it needs to wait for a resource, such
as waiting for user input, or waiting for a file to become available.
5 Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating
system, it is moved to the terminated state where it waits to be removed
from main memory.
Process Control Block (PCB)
• A Process Control Block is a data structure
maintained by the Operating System for every
process.
• The PCB is identified by an integer process ID
(PID).
• A PCB keeps all the information needed to
keep track of a process as listed below in the
table :
S.N. Information & Description
1 Process State
The current state of the process i.e., whether it is ready, running, waiting, or whatever.
2 Process privileges
This is required to allow/disallow access to system resources.
3 Process ID
Unique identification for each of the process in the operating system.
4 Pointer
A pointer to parent process.
5 Program Counter
Program Counter is a pointer to the address of the next instruction to be executed for this process.
6 CPU registers
Various CPU registers where process need to be stored for execution for running state.
9 Accounting information
This includes the amount of CPU used for process execution, time limits, execution ID etc.
10 IO status information
This includes a list of I/O devices allocated to the process.
Process Scheduling
• The process scheduling is the activity of the
process manager that handles the removal of the
running process from the CPU and the selection of
another process on the basis of a particular
strategy.
• Process scheduling is an essential part of a
Multiprogramming operating systems. Such
operating systems allow more than one process to
be loaded into the executable memory at a time
and the loaded process shares the CPU using time
multiplexing.
Process Scheduling Queues
3 In multiple processing environments, All threads can share same set of open
each process executes the same files, child processes.
code but has its own memory and
file resources.
6 In multiple processes each process One thread can read, write or change
operates independently of the another thread's data.
others.
Advantages of Thread
• Non-preemptive scheduling:
– The running process keeps the CPU until it
voluntarily gives up the CPU
• process exits 4
Terminated
Running
• switches to blocked state 1
3
• Transition 3 is only voluntary
• Preemptive scheduling: Ready Blocked
• Semaphore is just like this Key and the bike is the shared
resource. Whenever a task wants access to the shared resource, it
must acquire the semaphore first. The task should release the
semaphore after it is done with the shared resource. Till this time
all other tasks have to wait if they need access to shared resource
as semaphore is not available. Even if the task trying to acquire
the semaphore is of higher priority than the task acquiring the
semaphore, it will be in wait state until semaphore is released by
the lower priority task.
Use of Semaphore
1. Managing Shared Resource
2. Task Synchronization
Apart from managing shared resource, task synchronization
can also be performed with the help of a semaphore. In this case
semaphore will be like a flag not key.
Unilateral Rendezvous
– This is one way synchronization which uses a semaphore as a flag to
signal another task.
Bilateral Rendezvous
– This is two way synchronization performed using two semaphores. A
bilateral rendezvous is similar to a unilateral rendezvous, except both
tasks must synchronize with one another before proceeding.
Types of semaphore
1. Binary Semaphore
• Binary semaphore is used when there is only
one shared resource.
2. Counting Semaphore
• To handle more then one shared resource of
same type, counting semaphore is used.
3. Mutual Exclusion Semaphore or Mutex
• To avoid extended priority inversion, mutexes
can be used.
SEMAPHORE
• A semaphore is an integer variable taking on values from 0 to
a predefined maximum, each being associated with a queue
for process suspension. The order of process activation from
the queue must be fair.
• Two atomic operations that are indivisible and uninterruptible
are defined for a semaphore
• P() is wait
• V() is Signal
Deadlock
• Deadlock is the situation in which multiple
concurrent threads of execution in a system
are blocked permanently because of resource
requirements that can never be satisfied.
Deadlock
Deadlock Conditions
• Mutual exclusion-A resource can be accessed by only
one task at a time, i.e., exclusive access mode.
• No preemption-A non-preemptible resource cannot
be forcibly removed from its holding task. A resource
becomes available only when its holder voluntarily
relinquishes claim to the resource.
• Hold and wait-A task holds already-acquired
resources, while waiting for additional resources to
become available.
• Circular wait-A circular chain of two or more tasks
exists, in which each task holds one or more
resources being requested by a task next in the chain.
Avoid Deadlock
• Deadlocks can be avoided by avoiding at least one of the four
conditions
• Fourth Try
• sleep for Random interval
• Reduces the possibility for starvation
• Uses Mutex (Lock and UnLock)
• Prevents deadlock
Disadvantages of multitasking