Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Stephen Ferzetti
Topics
Why are Real Time Operating Systems Important Processes and Threads Scheduling Deadlocks
Nuclear Plant
Since the plant was running its anti-virus program at the time it missed its window Meltdown
Meeting deadlines Being able to break out of lower priority processes so that more important tasks can be accomplished When you break out of these processes that the data collected remains intact
What is a Process?
Whatis.com
Threads
A thread has a program counter that keeps track of which instruction to execute next. It also has memory to store the variables it is using
Process
Code Data Child Processes Resource List
Resources
Monitor Keyboard buffer
Process Thread
cout:you entered cin: input
cout: enter a number
Critical region
Process Creation
Processes are created when: The system is initialized A process creates another process The user requests a new process Initiation of a batch job
System Initialization
There are always processes running in the background so when the system starts these initial processes begin
A process that is running meets a condition that requires another process to run
Real World Example: A policeman is patrolling at night, then he sees something suspicious. He goes to investigate. If there is nothing he continues on his rounds. If there is something wrong he calls for backup and takes action.
The user can start up a new program which will spawn new processes
These programs may be something less important like opening an internet browser, or they may be critical and require immediate response like the triggering of an alarm
Process States
running 1 3 2 ready 4
1. 2. 3. 4.
Process blocks for input Scheduler picks another process Scheduler picks this process Input becomes available
blocked
Running
When a process is running that means that it is accessing the processor and that its code is executing Requirements The process must have all of its devices allocated, and it must not be waiting for any other processes to run
Ready
The ready condition is when the process has all of its resources allocated and it is not waiting on any other processes, and all that it is waiting for is to have processor time
Blocked
A process is blocked when either it is waiting on other processes to complete, or it has not been able to allocate all of the devices that it needs
Process Termination
Ways a process is terminated Normal exit (voluntary) Error exit (voluntary) Fatal error (involuntary) Killed by another process (involuntary)
Termination Example
Normal Exit The document prints Error Exit The printer is out of paper Fatal Error The computer crashes Killed by another process The User cancels the job
Scheduling
When multiple processes are in the ready state a scheduler is required The scheduler uses a scheduling algorithm to decide which process can enter the critical region
Non-preemptive Picks a process to run and will allow it to run forever until it chooses to end Preemptive Allows the process to run, but at anytime it can force the process to move into the ready state and allow another process to run
Deadlocks
Deadlock Condition when no processes will be completed because they cannot get the resources they require
All of these conditions must be true for a deadlock to occur: Mutual Exclusion resources may only be allocated to one process at a time Hold and Wait A process may allocate a resource and wait for others No Preemption A resource may not be forcibly taken away Circular Wait Processes
Mutual Exclusion
If a printer was not mutually exclusive to one process at a time then if 2 processes were printing at the same time then the output would blend together and be unreadable.
When reserving the resources not all of them need to be available at that time The process can hold on to the ones that are available and wait until the others become available
This is important because if a process were to wait to have everything it may never go into the ready state. This is because processes not requiring as much might continually jump in its position.
No Preemption
This means that a resource cannot be forcibly taken away from a process
If preemption for resources was allowed then processes could constantly take away from each other and never get to the processor, or a process that was running and whose time expired might still need that resource
Circular Wait
Circular wait means that processes are holding resources that other processes need
Deadlocks
Total Resources 1 printer 1 CD drive
Process A Holding: Printer Requesting: CD Drive
Ignore the problem Detection and recovery Dynamic avoidance by careful resource allocation Prevention, canceling one of the 4 conditions for deadlocks to occur
Ignoring
Ostrich Algorithm Do nothing If you know for a fact that a deadlock will occur very rarely, and the system is not a critical system you may choose to use this strategies This is totally unacceptable for RTOS because reliability is a major issue
Check and see if you are in a deadlock and attempt to get out of it
This means that the program will have to continually check and see if there is a deadlock This wastes too much time
Avoidance
This means that the program will continually check to see whether or not it is in a safe or unsafe condition Unsafe is if it is possible for a deadlock to occur Avoidance is also timely, but not as bad as detection and recovery
Prevention
To prevent a deadlock you must attack one of the conditions for a deadlock to occur
To attack the circular wait condition we place what resources need to be used in the order that they are used This means that the process cannot obtain any resource that is farther down before getting all the higher ones
This is the best strategy when using the real time operating system
The strategy here is requiring the process to hold all that it requires before entering accessing the processor
The reason this works best is because if the process states up front what it needs then there is a list of what each has Therefore if a process needs to be executed immediately then it can kill the processes holding the resources it needs and be run immediately
Smart sensors need to make decisions on their own Their decisions also need to be quick Also it is important that data be preserved
Decision Making
There must be a sense of priority, and there needs to be the ability to break out of processes to make deadlines Since real time systems have a clock specifically so that the system knows what time it is in the world around it is able to keep deadlines
Data Preservation
The systems use threading which can save all the current information even if the program is immediately ended This allows not only the quick response but also all the data at the occurrence to be saved
Example
An airplane has many sensors relaying data back to the pilot If something were to go wrong the sensors would need to send an error to the pilot, and take any other action (triggering an extinguisher) However it is almost as important that the sensors are able to record the data at the point of the problem so that the incident can be understood
Homework
Discuss the differences between preemptive and non-preemptive in relation to scheduling Pick a sensor you think would require a real time system and state why you picked it
Questions
References