Lecture 2 -Multitasking In The Operating Systems Flashcards
What is a program?
A program is the code a programmer writes.
What is a process?
A process is a program in execution, i.e., a particular instance of a program together with its data
Where does the OS store information about each process?
The OS stores information about each process in a process control block (PCB) or process descriptor
What is Multitasking?
Simultaneous running of two or more processes.
What is created by a user via a command?
- When a user initiates a program, OS creates a PCB data structureto represent the execution of this program.
- OS also allocates resources for the process.
- Process consists of machine code in memory and PCB.
What is created by a user process, called spawning a process?
- The process that creates a new process is called the parent while the created process child
- The child can also spawn new processes, forming a tree of processes
Why to run two or more processes at the same time?
- For convenience of the user (it is fun to work with a text editor, play chess, and watch a video at the same time)
- For a better CPU usage (when a program sends information to a printer, the CPU stays idle; it is good to load it with another program
What is the denition and role of interrupts?
- Interrupts: events that cause the CPU to stop the current execution and to start execute the program handling this interrupt.
- The program (let us call it Dispatcher) performs the operation required by the interrupt (say, sending data to a printer) and decides which process is the next to run.
.
What is the Dispatcher?
After the I/O system call or interrupt handling, control is passed to the dispatcher or Low Level Scheduler. The dispatcher works as below:
1) Is the current process still the most suitable to run? If so, return control to it; Otherwise . . .
2) Save the state of the current process in the PCB
3) Retrieve the state of the most suitable process
4) Transfer control to the newly selected process, at the point indicated by the restored program counter.
* This action of storing the state of current process and (re-)starting another process is called a context change.
What are the two main types of interrupts, states of processes?
Clock interrupt:
Initiated by a clock within CPU.
The means to stop run of the current process in order to give another one the right to run.
The process stopped by the Clock interrupt gets to the READY state
I/O interrupt:
Initiated by CPU that sees an I/O instruction in the program or by the I/O device to signal completion of the I/O operation.
When I/O operation starts the corresponding process gets to the BLOCKED.
When the I/O operation completes, the process becomes READY.
The dispatcher can select a process to run only if it is READY.
The running process is said to be in the RUNNING state
What is the story of interrupts?
A process can be in states RUNNING (currently running), READY
(ready to run) and BLOCKED (awaiting of completion of I/O).
Interrupts are used to stop the currently running process.
The clock interrupt causes the process to be READY.
The I/O interrupt causes the process to be BLOCKED, upon
completion it becomes READY
The Dispatcher chooses the next process to run from the queue of
READY processes.
The question of SCHEDULING: which process to choose?
What is the Scheduling policy denition and type?
Scheduling policy determines:
The next READY process to run.
The amount of time the process is given to occupy the CPU.
Non-preemptive scheduling:
A process releases CPU only if an I/O occurs or it nishes.
In other words, the process cannot be stopped during a regular
computation
Preemptive scheduling:
A process can be stopped at any moment.
To stop the process without I/O request a clock interrupt is used.
What are the 3 effciency measures of scheduling policies?
Turnaround time.
CPU usage.
Response time
What is Turnaround Time?
Turnaround time of a particular process is its duration, i.e. the difference between the end and the start times.
Turnaround time of a group of processes is the average of their individual turnaround times.
Example:
We have 3 processes with respective start and end times
(100;200), (150;300) and (200;400).
The individual turnaround times are 100, 150, 200.
The average turnaround time is 150
A good scheduling policy keeps average turnaround time as low as possible.