Title: Module 4: Processes
1Operating SystemsLecture 8 Processes II Read
Ch. 4.3 - 4.5
2Process Scheduling Queues
- Recall the process migration through multiple
queues - Job queue set of all processes in the system.
- Ready queue set of all processes residing in
main memory, ready and waiting to execute. - Device queues set of processes waiting for an
I/O device.
3Ready Queue And Various I/O Device Queues
4Representation of Process Scheduling
5Schedulers
- Long-term scheduler (or job scheduler)
- selects which processes should be brought into
the ready queue. - Is necessary when there are more processes
submitted than can be stored in memory. - Absent or minimal on some systems (e.g. UNIX)
- Short-term scheduler (or CPU scheduler)
- selects which process should be executed next
among processes in the ready queue. - Allocates the CPU to next process
- Medium-term scheduler (swapper)
- Temporarily removes process from memory and
stores it on disk. - Later the process can be swapped back in.
6Addition of Medium Term Scheduling
We will draw a new state diagram in class that
includes states for processes that have been
swapped out.
7Questions about Swapping
Why are there two suspend states instead of
one? When the OS needs memory, what processes
get suspended? When memory becomes available,
which processes have highest priority to be
placed in the ready queue?
8Frequency of Execution
- Short-term scheduler is invoked very frequently
- (milliseconds) ? (must be fast)
- If it executes 1 time per 100 msec and takes 10
msec to execute, what percentage of CPU time is
used by the scheduler? - Long-term scheduler is invoked very infrequently
- (seconds, minutes) ? (may be slow).
- The long-term scheduler controls the degree of
multiprogramming. - To keep the degree of multiprogramming stable,
the scheduler must bring in new processes as old
processes leave the system. - Medium term scheduler has an intermediate
frequency of execution.
9I/O bound vs. CPU bound
- A process may be described as I/O bound or CPU
bound. - I/O bound processes spend more time doing I/O
than using the CPU. - CPU bound processes spend more time doing
computation than using I/O - Process Mix
- Ideally we want a good balance between CPU bound
and I/O bound processes - What happens if all processes are I/O bound?
- What happens if all processes are CPU bound?
- Long term and medium term (swapper) schedulers
can be used to maintain a good process mix.
10Context Switch
- When CPU switches to another process, the system
must - save the state of the old process
- load the saved state for the new process.
- This is known as a context switch.
- The context of a process is represented by the
PCB. - Context-switch time is overhead the system does
no useful work while switching. - The speed is dependent on hardware support, and
may range between 1 and 1000 microseconds on
different machines. - Example The SUN UltraSPARC has multiple sets of
registers. To switch contexts, it just moves a
pointer to a new register set.
11Process Creation
- Parent processes create children processes,
which, in turn create other processes, forming a
tree of processes. - UNIX processes
- In UNIX, the swapper is the ancestor of all
processes. PID 0 (process ID) - The first child of the swapper is the INIT
process. PID 1 - The INIT process is the parent process to all
login processes.
12Diagram of UNIX Process tree
We will diagram this in class.
13Resources and Execution
- Resource sharing
- EITHER parent and children share all resources.
- Children share subset of parents resources.
- OR Parent and child share no resources.
- Why is it a good idea to restrict the child to a
subset of the parent's resources? - Execution
- EITHER Parent and children execute concurrently.
- OR Parent waits until some or all children
terminate.
14More on Child Processes
- Address space
- EITHER Child is a duplicate of the parent.
- OR Child has a program loaded into it.
- UNIX examples
- fork system call creates new process (duplicate
of parent). - exec system call used after a fork to replace the
process memory space with a new program. - (we'll see how these work later).
15Process Termination
- Normal Termination
- Process executes last statement and asks the
operating system to delete it (exit). - Output data from child to parent (via wait).
- Process resources are deallocated by operating
system.
16Other Modes of Termination
- Other modes of termination
- Parent may terminate execution of children
processes (abort). - Child has exceeded allocated resources.
- Task assigned to child is no longer required.
- Parent is exiting.
- Operating system may not allow child to continue
if its parent terminates. - Cascading termination.
- In UNIX--if the parent is terminated, the child
is adopted by INIT.