Process Description and Control

Download Report

Transcript Process Description and Control

Process Description and
Control
Chapter 3
Process Requirements of
an Operating System
Interleave execution of several processes
to maximize processor utilization while
providing reasonable response time
Allocate resources to processes
Support interprocess communication and
user creation of processes
Process
Also called a task or job
It is a program in execution
it is an active entity
Two-State Process Model
Dispatch
Enter
Not
Running
Running
Exit
Pause
State transition diagram
Queue
Enter
Dispatch
Exit
Processor
Pause
Queuing diagram
Reasons for Process
Creation
Submission of a batch job
User logs on
Created by OS to provide a service such
as printing
Spawned by an existing process
Reasons for Process
Termination
Normal completion
e.g., user logs off, requests termination
Error and fault conditions
e.g., time limit exceeded, memory
unavailable
OS intervention
e.g., when deadlock occurs
Parent request
Processes
Ready
prepared to execute
Blocked
waiting for I/O
Dispatcher cannot just select the process
that has been in the queue the longest
because it may be blocked
A Five-State Model
Running
process currently being executed
Ready
prepared to execute
Blocked
waiting for some event to occur
New
created but not admitted to job pool
Exit
released from job pool
Five-State Process Model
Dispatch
New
Admit
Ready
Release
Running
Time-out
Event
Occurs
Blocked
Event
Wait
Exit
Single Blocked Queue
Ready Queue
Release
Dispatch
Admit
Processor
Time-out
Event Wait
Event
Occurs
Blocked Queue
Multiple Blocked Queues
Ready Queue
Release
Dispatch
Admit
Processor
Time-out
Event 1 Wait
Event 1
Occurs
Event 1 Queue
...
Event n Wait
Event n
Occurs
Event n Queue
Suspended Processes
Processor is faster than I/O so all
processes could be waiting for I/O
Swap these processes to disk to free up
more memory
Blocked state becomes suspend state
when swapped to disk
Two new states
Blocked, suspend
Ready, suspend
Process State Transition Diagram
with Two Suspend States
Ne
w
Admit
Admit
Suspend
Dispatch
Activate
Ready,
suspend
Ready
Suspend
Time out
Event
Occurs
Event
Occurs
Activate
Blocked,
suspend
Running
Blocked
Event
Wait
Exit
Operating System Control
Structures
Tables are constructed for each entity the
operating system manages
memory tables
I/O tables
file tables
process tables
Memory Tables
Allocation of main memory to processes
Allocation of secondary memory to
processes
Protection attributes for main or virtual
memory
Information needed to manage virtual
memory
I/O Tables
I/O device is available or assigned
Status of I/O operation
Location in main memory being used as
the source or destination of the I/O
transfer
File Tables
Existence of files
Location on secondary memory
Current Status (e.g., open)
Attributes (e.g., permissions)
Sometimes this information is maintained
by a file-management system
Process Table
Process image is a collection:
user program
program or set of programs to be executed
user data
locations for local and global variables, defined
constants
run-time stack
LIFO stack to keep track of procedure calls,
parameters passed
process control block (PCB)
attributes used by the OS for process control
Contents of the Process
Control Block
Process identification
user id, process id, id of parent
Process state information
user visible registers
control and status registers
stack pointers
Contents of PCB (cont’d)
Process control information
scheduling and state information
data structuring
interprocess communication
process privileges
memory management
resource ownership and utilization
Typical Functions of an
Operating System Kernel
Process management
Memory management
I/O management
Support functions
Process Management
Process creation and termination
Process scheduling and dispatching
Process switching
Process synchronization and support for
inter-process communication
Management of process control blocks
Memory Management
Allocation of address space to processes
Swapping
Page and segment management
I/O Management and
Support Functions
Buffer management
Allocation of I/O channels and devices
to processes
Interrupt handling
Accounting
Monitoring
Steps in Process Creation
Assign a unique process identifier
Allocate space for the process
Initialize process control block
Set up appropriate linkages
e.g., add new process to linked list used for
scheduling queue
Other
maintain an accounting file
When to Context Switch
Interrupts
react to an asychronous external event
e.g., clock, I/O, memory fault
Trap
associated with execution of current
instruction
e.g, handle error or exceptional condition
Supervisor call
explicit request, e.g., open file
Steps in a Context Switch
Save context of “old” process
Update “old” PCB with the new state and
any accounting information
Move “old” PCB to appropriate queue
Select a “new’’ process for execution
Update PBC of “new” process
Update memory management tables
Restore context of “new” process
Execution of the OS
Nonprocess kernel
execute kernel outside of any process
OS code is executed as a separate entity that
operates in privileged mode
Execution within user processes
OS software within context of a user process
process executes in privileged mode when
executing OS code
Process-based operating system
major kernel functions are separate
processes
UNIX Process State
Transition Diagram
fork
Created
Preempted
return
to user
not enough memory
(swapping system only)
enough
memory
User
Running
preempt
return
system call,
interrupt
interrupt,
interrupt return
swap out
reschedule
process
Ready to Run
in Memory
Ready to Run
Swapped
swap in
Kernel
Running
sleep
wakeup
wakeup
exit
Zombie
Asleep in
Memory
swap out
Sleep,
Swapped