Process
Process
Process Scheduling
– Controls the execution of processes by allowing their creation, termination, suspension, and communication
– Schedules processes fairly for execution on CPU
∗ CPU executes a process
∗ Kernel suspends process when its time quantum elapses
∗ Kernel schedules another process to execute
∗ Kernel later reschedules the suspended process
– Allocates main memory for an executing process
∗ Swapping system: Writes entire process to the swap device
∗ Paging system: Writes pages of memory to the swap device
– Allocates secondary memory for efficient storage and retrieval of user data
– Allows controlled peripheral device access to processes
• Highest Level of User Processes: The shell in Unix
– Created for each user (login request)
– Initiates, monitors, and controls the progress for user
– Maintains global accounting and resource data structures for the user
– Keeps static information about user, like identification, time requirements, I / O requirements, priority, type of pro-
cesses, resource needs
– May create child processes (progenies)
• Process image
– Collection of programs, data, stack, and attributes that form the process
– User data
∗ Modifiable part of the user space
∗ Program data, user stack area, and modifiable code
– User program
∗ Executable code
– System stack
∗ Used to store parameters and calling addresses for procedure and system calls
– Process control block
∗ Data needed by the OS to control the process
– Location and attributes of the process
∗ Memory management aspects: contiguous or fragmented allocation
• File tables
– Information on file existence, location in secondary memory, current status, and other attributes
– Part of file management system
Process Id
Identification → Parent PID
User Id / Group Id
User registers
Program counter
CPU state → Condition codes
Status info (interrupt enable flags)
Stack pointer
Process state
Priority
Process scheduling → Wait-time
Event being waited on
Privileges
Flags
IPC → Signals
Messages
Unit Owned/
Memory → → ···
Description Shared
Resource Unit Owned/
Resources → → ···
Class Description Shared
Created resources → ↓ → ···
to resource
descriptor
Children
∗ Allocator
· Matches available resources to the requests from blocked processes
· Uses the inventory list and the waiting process list
∗ Additional Information
· Measurement of resource demand and allocation
· Total current allocation and availability of elements of the resource class
• Context of a process
– Information to be saved that may be altered when an interrupt is serviced by the interrupt handler
– Includes items such as program counter, registers, and stack pointer
P0 t0 i0 t1 i1 ··· in−1 tn
P0 t0 i0 t1 i1 · · · in−1 tn P0 terminated
P1 P1 waiting t00 i00 t01 i01 · · · i0m−1 t0m
P0 t0 t1 ··· tn
P1 t00 t01 ··· t0m
Process Scheduling 7
• Each entering process goes into job queue. Processes in job queue
– reside on mass storage
– await allocation of main memory
• Processes residing in main memory and awaiting CPU time are kept in ready queue
• Processes waiting for allocation of a certain I / O device reside in device queue
• Scheduler
– Concerned with deciding a policy about which process to be dispatched
– After selection, loads the process state or dispatches
– Process selection based on a scheduling algorithm
• Autonomous vs shared scheduling
– Shared scheduling
∗ Scheduler is invoked by a function call as a side effect of a kernel operation
∗ Kernel and scheduler are potentially contained in the address space of all processes and execute as a part of the
process
– Autonomous scheduling
∗ Scheduler (and possibly kernel) are centralized
∗ Scheduler is considered a separate process running autonomously
∗ Continuously polls the system for work, or can be driven by wakeup signals
∗ Preferable in multiprocessor systems as master/slave configuration
· One CPU can be permanently dedicated to scheduling, kernel and other supervisory activities such as I / O
and program loading
· OS is clearly separated from user processes
∗ Who dispatches the scheduler?
· Solved by transferring control to the scheduler whenever a process is blocked or is awakened
· Scheduler treated to be at a higher level than any other process
– Unix scheduler
∗ Autonomous scheduler
∗ Runs between any two other processes
∗ Serves as a dummy process that runs when no other process is ready
• Short-term v/s Long-term schedulers
– Long-term scheduler
∗ Selects processes from job queue
∗ Loads the selected processes into memory for execution
∗ Updates the ready queue
∗ Controls the degree of multiprogramming (the number of processes in the main memory)
∗ Not executed as frequently as the short-term scheduler
∗ Should generate a good mix of CPU-bound and I / O-bound processes
∗ May not be present in some systems (like time sharing systems)
– Short-term scheduler
∗ Selects processes from ready queue
∗ Allocates CPU to the selected process
∗ Dispatches the process
Process Scheduling 8
• Round-Robin Scheduling
6+4+7
Average waiting time = 3 = 5.66 milliseconds
– Let there be
n processes in the ready queue, and q be the time quantum, then
each process gets n1 of CPU time in chunks of at most q time units
Hence, each process must wait no longer than (n − 1) × q time units for its next quantum
– Performance depends heavily on the size of time quantum
∗ Large time quantum ⇒ FIFO scheduling
∗ Small time quantum ⇒ Large context switching overhead
∗ Rule of thumb: 80% of the CPU bursts should be shorter than the time quantum
• Real-time scheduling