Module 4: Processes

Download Report

Transcript Module 4: Processes

Operating Systems
Lecture 8
Processes II
Read Ch. 4.3 - 4.5
Operating System Concepts
4.1
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Process 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.
Operating System Concepts
4.2
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Ready Queue And Various I/O Device Queues
Operating System Concepts
4.3
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Representation of Process Scheduling
Operating System Concepts
4.4
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Schedulers
 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.
Operating System Concepts
4.5
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Addition of Medium Term Scheduling
We will draw a new state diagram in class that includes states for
processes that have been swapped out.
Operating System Concepts
4.6
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Questions 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?
Operating System Concepts
4.7
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Frequency 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.
Operating System Concepts
4.8
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
I/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.
Operating System Concepts
4.9
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Context 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.
Operating System Concepts
4.10
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Process 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.
Operating System Concepts
4.11
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Diagram of UNIX Process tree
We will diagram this in class.
Operating System Concepts
4.12
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Resources and Execution
 Resource sharing
 EITHER: parent and children share all resources.
Children share subset of parent’s 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.
Operating System Concepts
4.13
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
More 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).
Operating System Concepts
4.14
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Process 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.
Operating System Concepts
4.15
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Other 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.
Operating System Concepts
4.16
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005