The objectives of these slides are -
- To introduce the notion of a process - a program in execution, which forms the basis of all computation
- To describe the various features of processes, including scheduling, creation and termination, and communication
- To explore interprocess communication using shared memory and message passing
4. 4
Process Scheduling
• Single-processor system - not more than one running process
• Objective of multiprogramming - to maximize CPU utilization
• Objective of timesharing - to switch the CPU among processes, provide
user interaction
• Process Scheduler - selects an available process (possibly from a set of
several available processes) for program execution on the CPU
–Maintains scheduling queues of processes
5. 5
• Job queue – set of all processes in the system
• Ready queue – set of all processes residing in main memory, ready
and waiting to execute, and stored as linked list
• Device queues – set of processes waiting for an I/O device
• Suppose the process makes an I/O request to a shared device,
such as a disk.
• Processes migrate among the various queues
5
7. 7
• Representation of process scheduling is a Queueing diagram
• Rectangle represents- queue
• Circle represents –resources
• Arrow represents –flow
• Two types of queues (in fig. Queueing-diagram representation of
process scheduling)
• the ready queue and
• a set of device queues
• A new process is initially put in the ready queue, waits there until it is
selected for execution, or dispatched
7
8. 8
• Once the process is allocated the CPU and is executing, one of several
events could occur:
• The process could issue an I/O request and then be placed in an
I/O queue
• The process could create a new child process and wait for the
child’s termination.
• The process could be removed forcibly from the CPU, as a result
of an interrupt, and be put back in the ready queue
8
Switching
happens
10. 10
• Processes migrate among the various scheduling queues
• The selection process of scheduling purposes, processes from the
queues carried out by Scheduler
• Long-term scheduler (or) job scheduler
• selects which processes should be brought into the ready queue
• invoked infrequently (seconds, minutes) (may be slow)
• controls the degree of multiprogramming (the number of
processes in memory) needs to be stable
• strives for good process mix
10
11. 11
• Short-term scheduler (or) CPU scheduler
• selects processes that are ready to execute and allocates CPU to
one of them
• invoked frequently (milliseconds) (must be fast)
• short time between executions - executes at least once every
few milliseconds
• Processes can be described as either:
• I/O-bound process – spends more time doing I/O than
computations, many short CPU bursts
• CPU-bound process – spends more time doing computations;
few very long CPU bursts
11
12. 12
• What happens if all the processess are I/O bound?
• What happens if all the processess are CPU bound?
• Systems with best performance will have a combination of CPU-
bound and I/O-bound processes
12
13. 13
• Time-sharing systems introduces an additional, intermediate level
of scheduling - Medium-term scheduler
• Key idea is to reduce the degree of multiprogramming
• Remove process from memory, store on disk, bring back in from
disk to continue execution - Swapping
• to improve the process mix
13
15. 15
Multitasking in mobile systems
• Some mobile systems (e.g., early version of iOS) allow only one
process to run, others suspended
• Due to screen real estate, user interface limits iOS provides for a
• Single foreground process- controlled via user interface
• Multiple background processes– in memory, running, but not on the display,
and with limits
• Limits include single, short task, receiving notification of events, specific
long-running tasks like audio playback
• Android runs foreground and background, with fewer limits
• Background process uses a service to perform tasks
• Service can keep running even if background process is suspended
• Service has no user interface, small memory use
15
16. 16
Context Switch
• When CPU switches to another process, the system must save the
state of the old process and load the saved state for the new
process via a context switch
• Context of a process represented in the PCB
• Context-switch time is overhead; the system does no useful work
while switching
• The more complex the OS and the PCB the longer the context
switch
• Time dependent on hardware support
• Some hardware provides multiple sets of registers per CPU
multiple contexts loaded at once
16