Download Chapter 3 Process Description and Control Major

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Unix security wikipedia , lookup

Distributed operating system wikipedia , lookup

Burroughs MCP wikipedia , lookup

DNIX wikipedia , lookup

Process management (computing) wikipedia , lookup

Transcript
2/3/2014
Operating Systems:
Internals and Design Principles, 6/E
William Stallings
Chapter 3
Process Description and Control
Major Functions 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
Patricia Roy
Manatee Community College, Venice, FL
©2008, Prentice Hall
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
Process Elements (I)
•
•
•
•
•
Identifier
State
Priority
How to describe a process?
Program counter
What elements are included in
Memory pointers: to code and data
it?
– the execution of a sequence of instructions
– a current state
– an associated set of system resources
Process Elements (II)
• Context data: value of CPU registers
• I/O status information
– Outstanding I/O requests
– Assigned I/O devices and used files
Process Control Block
• Contains the process elements
• Created and managed by the operating
system
• Accounting information
– Amount of processor time & clock time used
– Time limits
– Account numbers
1
2/3/2014
Process Control Block
• Allows support
for multiple
processes
Trace of the Process
• Sequence of instruction that execute for a
process
• Dispatcher switches the processor from
one process to another
Example Execution
Trace of Process
Combined Trace of Process
Two-State Process Model
• Process may be in one of two states
– Running
– Not-running
2
2/3/2014
Queuing Diagram
Process Creation (I)
Example: Application Modularity
Example: Concurrent Server
Dispatcher
process
Request dispatched to a
worker process
Server
Worker
process
Process Creation (II)
Process Termination
• What does the OS do to create a process?
– Build data structures that are used to manage
the process;
– Allocate address space in main memory to
the process.
3
2/3/2014
Process Termination
Queuing Diagram
Queuing
A Five-State Model
• Processes
– Not-running ready to execute
– Not-running block
– Dispatcher must scan list to find process notrunning, ready, and in queue the longest
Five-State Process Model
•
•
•
•
•
Running
Ready
Blocked
New
Exit
Process States
4
2/3/2014
Using Two Queues
Multiple Blocked Queues
Suspended Processes
Two Suspend States
• Processor is faster than I/O so all
executable processes could be waiting for
I/O, while there are some new processes
waiting to be admitted
• Swap these processes to disk to free up
more memory to admit new processes
• Blocked state becomes suspend state
when swapped to disk
• Two new states
– Blocked/Suspend
– Ready/Suspend
Reason for Process
Suspension
Processes and Resources
5
2/3/2014
In-Class Exercise
Running
1
Blocked
2
6
5
3
4
1: process blocks for input
2: scheduler picks another process
3: scheduler picks this process
4: input becomes available
5: process blocks for input
6: input becomes available
Ready
Which state
transition is
impossible?
Operating System Control
Structures
OS Control Tables
• Information about the current status of
each process and resource
• Tables are constructed for each entity the
operating system manages
• So, what control tables does an OS have
Memory Tables (1)
• Used to keep track of both main (real)
memory and secondary (virtual) memory
• Some of main memory reserved for OS
• The remainder is available for processes
• Processes are maintained on secondary
memory
Memory Tables (2)
• 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
6
2/3/2014
I/O Tables
• Used by OS to manage 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
Process Tables
File Tables
•
•
•
•
•
Existence of files
Location on secondary memory
Current Status
Attributes
Sometimes this information is maintained
by a file management system, OS has little
or no knowledge of files
• In other OS, detailed file management is
by OS itself
Process Stack
• Manage processes
• What is a process composed of?
• Process image is the collection of
program, data, stack, and attributes
Figure 4-5. (a) Parameter passing in a procedure call: the
stack before the call to read. (b) The stack while the called
procedure is active.
Process Location
Process Images
• Where are the processes located?
– Secondary memory, usually disk
– To manage and execute a process, at least a
small portion of its image must be maintained
in main memory
• OS must know the location of each page
of each process image, achieved by
process tables
7
2/3/2014
PCB: Process Control
Information
PCB: 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.
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
When to Switch Process
• Clock interrupt
– process has executed for the maximum
allowable time slice
• I/O interrupt
• Memory fault
– memory address is in virtual memory so it
must be brought into main memory
Process Creation
•
•
•
•
•
Assign a unique process identifier
Allocate space for the process
Initialize process control block
Set up appropriate linkages
Create or expand other data structures
When to Switch Process
• Trap
– error or exception occurred
– may cause process to be moved to Exit state
• Supervisor call (system call)
– I/O operation such as file open
– Lead to a transfer to an OS routine
8
2/3/2014
How to Switch Process?
Process Switch (1)
• 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
• Move process control block to appropriate
queue – ready; blocked; ready/suspend
Process Switch (2)
• Select another process for execution
• Update the process control block of the
process selected
• Update memory-management data
structures
– Depending on how address translation is
managed, memory management data
structures need to be updated
Execution of the Operating
System
• Non-process Kernel
– Execute kernel outside of any process
– Operating system code is executed as a
separate entity that operates in privileged
mode
• Execution Within User Processes
– Operating system software within context of a
user process
• Restore context of the selected process
Execution of the Operating
System
Execution of the Operating
System
• Process-based operating system
– Implement the OS as a collection of system
processes
9
2/3/2014
OS Executes in User Space
• Process Switch
vs.
• Mode Switch
Process Switch (1)
• 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
• Move process control block to appropriate
queue – ready; blocked; ready/suspend
Mode Switch
Process Switch (2)
• Select another process for execution
• Update the process control block of the
process selected
• Update memory-management data
structures
• Restore context of the selected process
UNIX Process States
• Save context of processor including
program counter and other registers
• Update the process control block of the
running process
• Mode changes to kernel mode, finishes the
OS routine
• Mode changes back, restore the context,
and continue the running process in user
mode
10
2/3/2014
UNIX Process State
Transition Diagram
fork()
• Process creation in Unix is made by means of the
kernel system call, fork()
• When a process issues a fork request, the OS:
– Allocates a slot in the process table for the new process;
– Assigns a unique process ID to the child process;
– Makes a copy of the process image of the parent, with the
exception of any shared memory;
– Increments counters for any files owned by the parent, to reflect
that an additional process now also owns those files;
– Assigns the child process to the Ready to Run state;
– Returns the ID number of the child to the parent process, and a 0
value to the child process.
Reminder
• 13 students still haven’t formed project
teams
• Team needs to be formed by this Friday!
Appendix
Elements of a Process
Control Block
• How to assign a process an identifier?
• may be an index into the process table
• or process identifier  process table index
• useful for cross-reference by other tables,
inter-process communication
11
2/3/2014
Elements of a Process
Control Block
Review Questions
• What does it mean to preempt a process?
• What is swapping and what is its purpose?
• For what types of entities does the OS
maintain tables of information for
management purposes?
• List three general categories of information
in a process control block.
12