Week 5 - Processes and Scheduling Flashcards
process
is a program in execution.
process vs program
program is a passive entity a sequence of instructions.
process is an active entity – it is “doing things”. It is an executing part of a program.
Several copies of the same program may be running concurrently – each in a distinct process.
process also contains execution state.
Memory layout of a Process
Text Section: the executable code
Data Section: contains global and static variables
Heap: memory that is dynamically allocated during program run time
Stack: temporary data storage when invoking functions (such as function parameters, return addresses, and local variables)
What Makes a Process?
program counter (point reached in programme), a stack and a data section
address space of a process is another of its defining properties:
Process = Thread(s) + Address Space
Multitasking
Operating system is responsible for sharing the physical CPU resource between processes through time-sharing.
Context switching between processes happens frequently enough that processes appear to run concurrently. Context switching is the process of storing the state of a process and switch the CPU to another process.
- Maximum quantum of time a process runs before switching might be around 10ms. Details depend on OS scheduling policy.
Time Sharing
While one process is waiting for I/O, the CPU can be reallocated to another process that has work to do, and improves utilization of CPU.
Should context switch, process has been executing on the CPU for an allocated quantum.
Process needs to wait for I/O - relinquish CPU to another process.
Process States
New: The process is being created.
Ready: The process is waiting to be assigned to a processor.
Running: Instructions are being executed.
Blocked/Waiting: The process is waiting for some event to occur(such as an I/O completion or reception of a signal)
Terminated: The process has finished execution.
Process States example (Slide (13, 14,15)
Process Table
The operating system maintains a data structure (process table) in memory with slots for every running process.
Slot for each process is called a Process Control Block (PCB).
Process Control Block (PCB)
For processes not presently in running state, a PCB includes:
Contents of all machine registers at time process was interrupted
general purpose registers, program counter, program status word, etc
PCB does not contain program variables – these are assumed still in process’ memory.
Dispatcher
Part of the OS called the dispatcher gives control of the CPU to the process selected by the scheduler.
involves:
Stopping the currently running process,
Storing the hardware registers (PC, SP, etc.), and any other state information in that process’ PCB,
Loading the hardware registers with the values stored in the selected process’ PCB, and restores any other state information,
Switching to user mode,
Jumping to the proper location in the user program to restart that program.
Multitasking Summary
The first step of context switching is typically a call to an interrupt handler.
Process table slot for the formerly running process is added to the back of a queue.
- Either of blocked or ready processes
The scheduler chooses a new process to run from the front of ready queue.
Scheduling Issues
When should the CPU be given to another process?
Under what circumstances should the CPU be given to another process (scheduling policy) ?
How long and in what order should the CPU be given to another process (scheduling mechanism) ?
Scheduler
Conceptually, ready processes are on a ready queue.
Assumes all processes are in memory,
Scheduler selects a process from the ready queue and allocates the CPU to it.
More on Queues
Ready queue is usually implemented using “linked list” data structure
- linked list of pointers to PCB’s.
Since there is generally contention for I/O, each device also has a queue
Likewise there may process queues associated with semaphores, etc