Download Process Description and Control

Document related concepts

Distributed operating system wikipedia , lookup

Burroughs MCP wikipedia , lookup

DNIX wikipedia , lookup

Process management (computing) wikipedia , lookup

Transcript
Process Description and Control
Chapter 3
1
Requirements of an
Operating System
• Interleave the execution of multiple
processes to maximize processor
utilization while providing reasonable
response time
• Allocate resources to processes
• Support interprocess communication and
user creation of processes
2
Process
• A program in execution
• An instance of a program running on a
computer
• The entity that can be assigned to and
executed on a processor
• A unit of activity characterized by the
execution of a sequence of instructions,
a current state, and an associated set of
system instructions
3
Process Elements
• At any given time, while the program is executing, this
process can be uniquely characterized by a number of
elements, as below:
• Identifier(a unique id to distinguish it from all other
process).
• State(process is executing it is in running state)
• Priority(Priority level relative to other processes)
• Program counter(address of the next instruction to be
executed)
• Memory pointers(pointers to the program code and
data associated with this process and if nay memory
blocks shared with other process)
4
Process Elements
• Context data (processor’s register data
when the process is executed)
• I/O status information( Includes
outstanding I/O requests,I/O devices(e.g.
tape drives) assigned to this process,
alist of files in use by the process etc)
• Accounting information(includes
amount of processor time and clock time
used,time limits,account numbers etc)
5
Process Control Block
• Contains the process elements
• Created and manage by the operating
system
• Allows support for multiple processes
6
Process Control Block
Identifier
State
Priority
Program counter
Memory pointers
Context data
I/O status
information
Accounting
information
Figure 3.1 Simplified Process Control Block
7
Trace of Process
• Sequence of instruction that execute for
a process
• Dispatcher switches the processor from
one process to another
8
Two-State Process Model
• Process may be in one of two states
– Running
– Not-running
9
Not-Running Process in a
Queue
10
Process Creation
11
Process Termination
12
13
Processes
• Not-running
– ready to execute
• Blocked
– waiting for I/O
• some processes in the Not Running state are ready to execute, while others
are blocked, waiting for an I/O operation to complete.
• Thus, using a single queue, the dispatcher could not just select the process at
the oldest end of the queue.
• To handle this situation is to split the Not Running state into two states:
• Ready
• Blocked.
• we have added two additional states that will prove useful.
14
A Five-State Model
• Running (process that is currently executed)
• Ready (prepared to execute when given the opportunity
• Blocked (cannot be executed until some event occurs)
• New (a process that is created but has not yet been admitted to the
pool of executable process by the OS. A new process has not yet
been loaded into Memory Management, although its PCB has
been created)
• Exit ( a process is released from the pool of executable process by
the OS,either because it halted or aborted)
15
Five-State Process Model
• The five states in this new diagram are as follows:
16
Using Two Queues
17
Multiple Blocked Queues
Release
Ready Queue
Admit
Dispatch
Processor
Timeout
Event 1 Queue
Event 1
Occurs
Event 1 Wait
Event 2 Queue
Event 2 Wait
Event 2
Occurs
Event n Queue
Event n
Occurs
Event n Wait
(b) Multiple block ed queues
18
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
19
We have two new state with five state model
as below:
– Blocked /Suspend : Process is in secondary
memory and awaiting an event.
– Ready/Suspend : Process is in secondary
memory but is available for execution as
soon as it is loaded into memory.
20
One Suspend State
21
Two Suspend States
22
Characteristics of a suspended
Process
1. Process is not immediately available for execution.
2. Process may or may not be waiting on an event.
3. Process was placed in a suspended state by an agent
: either itself , a parent process, or the operating
system,for the purpose of preventing its execution.
4. Process may not be removed form this state until
the agent explicitly orders the removal.
23
Reasons for Process Suspension
24
Process Description
25
Processes and Resources
26
Operating System Control
Structures
• Information about the current status of
each process and resource
• Tables are constructed for each entity the
operating system manages
27
Memory Tables
Process
1
Memory
Devices
Process
Image
I/O Tables
Files
Processes
File Tables
Primary Process Table
Process 1
Process 2
Process 3
Process
Image
Process
n
Process n
Figure 3.11 General Structure of Operating System Control Tables
28
Memory Tables
• Used to keep track of both main and secondary
memory
Memory tables must include the following
information :
• Allocation of main memory to processes
• Allocation of secondary memory to processes
• Protection attributes for access to shared memory
regions
• Information needed to manage virtual memory
29
I/O Tables
• Used by the OS to manage the I/O
devices and channels of the computer
system.
• 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
30
File Tables
•
•
•
•
•
Existence of files
Location on secondary memory
Current Status
Attributes
Sometimes this information is
maintained by a file management system
31
Process Table
• Where process is located
• Attributes in the process control block
– Program
– Data
– Stack
To create tables the OS must have some
knowledge about the capacity of the
MM,what I/O devices are connected and
their identifiers and so on.
32
Process Control Structures
If the OS has to manage and control a
process it must know
• Where the process is located
• Attributes of the process that are
necessary for its management.
(e.g process ID,process state,location in
memory ).
33
Process Image
• The collection of program,data,stack and
attributes are referred to as the process
image.
34
Process Image
35
3 categories of PCB(general)
• 1. Process identification
• 2. Processor State Information
• 3. Process Control Information
36
Process Control Block
• Process identification
– Identifiers
• Numeric identifiers that may be stored with the
process control block include
– Identifier of this process
– Identifier of the process that created this process
(parent process)
– User identifier
37
Processor State Information
• Contents of processor registers
– User-visible registers
– Control and status registers
– Stack pointers
• Program status word (PSW)
– contains status information
– Example: the EFLAGS register on Pentium
machines
38
Process Control Block
• Processor State Information
– User-Visible Registers
• A user-visible register is one that may be
referenced by means of the machine language
that the processor executes while in user mode.
Typically, there are from 8 to 32 of these
registers, although some RISC implementations
have over 100.
39
Process Control Block
• Processor State Information
– Control and Status Registers
These are a variety of processor registers that are
employed to control the operation of the processor. These
include
• Program counter: Contains the address of the next
instruction to be fetched
• Condition codes: Result of the most recent arithmetic or
logical operation (e.g., sign, zero, carry, equal, overflow)
• Status information: Includes interrupt enabled/disabled
flags, execution mode
40
Process Control Block
• Processor State Information
– Stack Pointers
• Each process has one or more last-in-first-out
(LIFO) system stacks associated with it. A stack
is used to store parameters and calling addresses
for procedure and system calls. The stack
pointer points to the top of the stack.
41
Process Control Block
• Process Control Information
– Scheduling and State Information
This is information that is needed by the operating system to perform its
scheduling function. Typical items of information:
•Process state: defines the readiness of the process to be scheduled for
execution (e.g., running, ready, waiting, halted).
•Priority: One or more fields may be used to describe the scheduling
priority of the process. In some systems, several values are required (e.g.,
default, current, highest-allowable)
•Scheduling-related information: This will depend on the scheduling
algorithm used. Examples are the amount of time that the process has
been waiting and the amount of time that the process executed the last
time it was running.
•Event: Identity of event the process is awaiting before it can be resumed
42
Process Control Block
• Process Control Information
– Data Structuring
• A process may be linked to other process in a queue,
ring, or some other structure.
• For example, all processes in a waiting state for a
particular priority level may be linked in a queue.
• A process may exhibit a parent-child (creator-created)
relationship with another process.
• The process control block may contain pointers to other
processes to support these structures.
43
Process Control Block
• Process Control Information
– Interprocess Communication
• Various flags, signals, and messages may be associated
with communication between two independent processes.
Some or all of this information may be maintained in the
process control block.
– Process Privileges
• Processes are granted privileges in terms of the memory
that may be accessed and the types of instructions that
may be executed. In addition, privileges may apply to the
use of system utilities and services.
44
Process Control Block
• Process Control Information
– Memory Management
• This section may include pointers to segment
and/or page tables that describe the virtual
memory assigned to this process.
– Resource Ownership and Utilization
• Resources controlled by the process may be
indicated, such as opened files. A history of
utilization of the processor or other resources
may also be included; this information may be
needed by the scheduler.
45
Modes of Execution
• User mode
– Less-privileged mode
– User programs typically execute in this
mode
• System mode, control mode, or kernel
mode
– More-privileged mode
– Kernel of the operating system
46
Process Creation
• Assign a unique process identifier :a new entry
is added to the primary process table,which
contains one entry per process
• Allocate space for the process : includes all
elements of the process image .
– OS must know how much space is needed for the private user
address space(programs and data) and the user stack.
– If a process is spawned by another process,the parent process
can pass the needed values to the OS as a part of the processcreation request.
– If any existing address space is to be shared by this new
process,the appropriate linkages must be set up.
– Space for a process control block must be allocated.
47
• Initialize process control block : Process identification
contains the ID of this process plus other appropriate
IDs( parent process).
• The processor state information portion will typically
be initialized with most entries zero,except for the
program counter(set to the program entry point) and
system stack pointers (set to define the process stack
boundaries).
• The process control information portion is initialized
based on std default values plus attributed that have
been requested for this process.
48
• Set up appropriate linkages
– Ex: add new process to linked list used for
scheduling queue
• Create or expand other data structures
– Ex: maintain an accounting file
49
When to Switch a Process
A process switch may occur any time that the os has gained
control from currently running process.
• Clock interrupt
– process has executed for the maximum allowable time slice
• I/O interrupt
• The OS determines what I/O action has occurred.
• If the I/O action form an event for which one or more
processes are waiting, then the OS moves all of the
corresponding blocked process to the ready state.
• Memory fault
– memory address is in virtual memory so it must be brought into
main memory
50
When to Switch a Process
• Trap
– error or exception occurred
– may cause process to be moved to Exit state
• Supervisor call
– The OS may be activated by a supervisor call from
the program being executed.
– E.g. a user process is running and an instruction is
executed that requests an I/O operation.
51
Change of Process State
The steps involved in a full process switch are as follows:
• Save context of processor including program counter and other
registers
• Update the process control block of the process that is currently in
the Running state
• Other relevant fields must also be updated, including the reasons
foe leaving the running state and accounting information.
• Move process control block to appropriate queue – ready; blocked;
ready/suspend
• Select another process for execution
52
Change of Process State
• Update the process control block of the process
selected
• Update memory-management data structures
• Restore context of the selected process to the
which existed at the selected process was last
switched out of the running state.
53
UNIX SVR4 Process
Management
• Most of the operating system executes within
the environment of a user process
P1
OS
Functions
P2
OS
Functions
Pn
OS
Functions
Process Switching Functions
(b) OS functions execute within user pr
54
Process creation in Unix
Process creation in Unix is made by means of the Kernel system call,
fork(). When a process issues a fork request ,the OS performs the
following functions :
1. It allocates a slot in the process table for the new process.
2. It assigns a unique process ID to the child process.
3. It makes a copy of the process image of the parent.
4. It increments counters for any files owned by the parent ,to reflect
that
an additional process now also owns those files.
5. It assigns the child process to a ready to run state
6. It returns the ID number of the child to the parent process, and a 0
value to the child process.
All this work is accomplished in Kernel mode in the parent process.
55
UNIX Process States
56
UNIX Process Image
57
58