Processes: Abstract Model & Implementation
Topics
This set of slides amounts to an outline of topics from Chapter 3
of the textbook. The figures and tables are also taken from the
textbook. For the corresponding detailed narrative, you can read the
text directly. When I covered the previous generation of these slides
in class, the previous term this course was offered, I felt I was
wasting class time, since the material is explained perfectly well in
the text. I have posted them here for the benefit of those who may
find them useful. If we have enough time in class left after the
Unix-specific material you need for your programming assignments, I
may use them, but it is very unlikely we will cover all of them in
class. Do not be misled by this into thinking you are not expected to
read Chapter 3 of the textbook.
Major Requirements of an Operating System
- Interleave the 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
Why do we need multiple processes?
The main reason is that the I/O activities are much slower
than computation, so if we did not have the ability to interleave execution
of more than one process the processor would be
idle (waiting for I/O operations to complete) most of the time.
- Sometimes also called a task -- but not in this course!
- Execution of an individual program
- Can be traced
- list the sequence of instructions that execute
Varying Terminology -- A Problem for Students
- authors use terms with different meanings
- some examples of problem terms:
- task, process, thread, job
- interrupt, signal, exception, trap
Processes in a Non-Virtual Memory System
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
This example supposesx the processes are implemented without virtual
memory, so the real (physical) memory addresses are used. Please do
not be confused by this. In our discussion of Unix processes we have
assumed each process has its own independent logical address space.
The textbook will get around to that (more modern) model later. The
author just chooses to start by explaining how processes work with
this older, more primitive memory model.
Traces of Individual Processes
Trace of Process A | Trace of Process B | Trace of Process C |
---|
5000 | 8000 | 12000 |
5001 | 8001 | 12001 |
5002 | 8002 | 12002 |
5003 | 8003 | 12003 |
5004 | | 12004 |
5005 | | 12005 |
5006 | | 12006 |
5007 | | 12007 |
5008 | | 12008 |
5009 | | 12009 |
5010 | | 12010 |
5011 | | 12011 |
Combined Traces of Processes
Inst. Cycle | Inst. Address | | | Inst. Cycle | Inst. Address | |
1 | 5000 | | | 27 | 12004 | |
2 | 5001 | | | 28 | 12005 | |
3 | 5002 | | | -- | -- | Time out |
4 | 5003 | | | 29 | 100 | |
5 | 5004 | | | 30 | 101 | |
6 | 5005 | | | 31 | 102 | |
-- | -- | Time out | | 32 | 103 | |
7 | 100 | | | 33 | 104 | |
8 | 101 | | | 34 | 105 | |
9 | 102 | | | 35 | 5006 | |
10 | 103 | | | 36 | 5007 | |
11 | 104 | | | 37 | 5008 | |
12 | 105 | | | 38 | 5009 | |
13 | 8000 | | | 39 | 5010 | |
14 | 8001 | | | 40 | 5011 | |
15 | 8002 | | | -- | -- | Time out |
16 | 8003 | | | 41 | 100 | |
-- | -- | I/O request | | 42 | 101 | |
17 | 100 | | | 43 | 102 | |
18 | 101 | | | 44 | 103 | |
19 | 102 | | | 45 | 104 | |
20 | 103 | | | 46 | 105 | |
21 | 104 | | | 47 | 12006 | |
22 | 105 | | | 48 | 12007 | |
23 | 12000 | | | 49 | 12008 | |
24 | 12001 | | | 50 | 12009 | |
25 | 12002 | | | 51 | 12010 | |
26 | 12003 | | | 52 | 12011 | |
| | | | - | - | Time out |
Orange shaded areas indicate execution of the dispatcher.
Two-State Process Model
Process may be in one of two states:
Two-State Process Model
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Queue for Not-Running Processes
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Reasons for Process Creation
examples:
- Submission of a batch job
- User logs on
- Created to provide a service such as printing
- Process creates another process
Reasons for Process Termination
- Normal completion
- Time limit exceeded
- Memory unavailable
- Bounds violation
- Protection error - example write to read-only file
- Arithmetic error
- Time overrun - process waited longer than a specified maximum for an event
- I/O failure
- Invalid instruction - e.g., program tries to execute data
- Privileged instruction
- Data misuse
- Operating system intervention - e.g., deadlock occurs
- Parent terminates so child processes terminate
- Parent request
A Closer Look at Not-Running Processes
- Not-running, ready to execute
- Not-running, 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 Process Model
- Running
- Ready
- Blocked
- New
- Exit
Five-State Process Model
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Process States for Trace Shown Earlier
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Adding a Queue for Blocked Processes
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Multiple Event Queues
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Suspended Processes
- Suppose we want to load a new process, or resident processes need more memory
- Can swap some processes to disk to free up more memory
- Blocked state becomes suspend state when swapped to disk
- Two new states:
- Blocked, suspend
- Ready, suspend
Suspended State
- not available for execution (since not in main memory)
- may or may not be waiting for an event
- placed in this state by an agent, to prevent execution
- may not be removed from this state until the agent orders it
Terminology Warning:
This usage of "suspend" is not universal.
Some authors use the term slightly differently.
Process Model with One Suspend State
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Process Model with Two Suspend States
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Reasons for Process Suspension
- Swapping
- OS needs memory for another process
- Other OS Reason
- operator intervention, performance tuning, etc.
- Interactive User Request
- e.g., CTL-I from terminal
- Timing
- process requests sleep until specified time
- Parent process request
- job control
Processes & Resources
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Shows snapshot of resource allocation at one instant in time.
Operating System Control (Internal) Data Structures
- Hold information about the current status of each process and resource
- A data object is constructed for each entity the operating system manages
Memory Tables
- 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
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
File Tables
- Existence of files
- Location on secondary memory
- Current Status
- Attributes
- Sometimes this information is maintained by a file-management system
Process Table
- Where process is located
- Attributes necessary for its management, e.g.
- Process ID
- Process state
- Location in memory
Process Location
- Process includes set of programs to be executed
- Data locations for local and global variables
- Any defined constants
- Stack
- Process control block
- Process image
- Collection of program, data, stack, and attributes
Operating System Control Tables
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
- Process identification
- Processor state information
- Process control information
Process Control Block - Process Identification
Information that may be stored in the process control block includes:
- Identifier of this process
- Identifier of the process that created this process (parent process)
- User identifier
Process Control Block - Processor State Information
- User-Visible Registers
- may be referenced by means of the machine
language that the processor executes
- typically, there are from 8 to 32 of these registers
- some RISC implementations have over 100
- Control and Status Registers - control the operation of the processor
- 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)
- Stack top pointer, activation record base pointer
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.
Process Control Block - Process Control Information
- Scheduling and State 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.
- Data Structure Links
The process state and other scheduling information is needed by the
OS to perform its scheduling function.
Process Control Block - More 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.
- 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.
User Processes in Virtual Memory
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Processor State Information - Registers
- 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
Pentium II EFLAGS Register
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
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
Process Creation
- Assign a unique process identifier
- Allocate space for the process
- Initialize process control block
- Set up appropriate linkages
- Ex: add new process to linked list used for scheduling queue
- Create of expand other data structures
- Ex: maintain an accounting file
When to Switch a 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
- Trap
- error occurred
- may cause process to be moved to Exit state
- Supervisor call
Change of Process State
- Save context of processor including program counter and other
registers
- Update the process control block of the process that is currently
running
- Move process control block to appropriate queue - ready,
blocked
- 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
- Non-process Kernel
- Execution Within User Processes
- Process-Based Operating System
Note:These are idealized models. An actual OS will typically use a
combination of these models.
Non-process Kernel
- execute kernel outside of any process
- operating system code is executed as a separate entity that operates in
privileged mode
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
OS Functions Execute Within User Processes
- operating system software within context of a user process
- process executes in privileged mode when executing operating system code
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Process Image - OS Executes in User Space
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Process-Based Operating System
- OS Functions Execute as Separate Processes
- major kernel functions are separate processes
- Useful in multi-processor or multi-computer environment
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
UNIX SVR4 Process Management
- Most of the operating system executes within the environment of
a user process
- User Running
- executing in user mode
- Kernel Running
- executing in kernel mode
- Ready to Run, in Memory
- ready to run as soon as kernel schedules it
- Asleep in Memory
- waiting for an event, and in memory
- Ready to Run, Swapped
- not in memory; must be swapped in to run
- Sleeping, Swapped
- waiting for an event, and not in memory
- Preempted
- returning from kernel mode; kernel scheduled a higher priority process
- Created
- exists, but not yet ready to run
- Zombie
- terminated, but exit status is held for parent to collect
Unix Process State Transition Diagram
Figure © Prentice Hall. Reproduced here from
Operating Systems, Internals and Design Principles (4th Edition) by permission
of publisher.
Figures and tables © Prentice Hall. Topic outline abstracted from
Operating Systems, Internals and Design Principles © Prentice Hall
starting from Powerpoint Slides originally prepared by Patricia Roy © Prentice Hall.
New content © 2002, 2005
T. P. Baker &
Florida State University.
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means without written permission.
(Last updated by $Author: cop4610 $ on $Date: 2002/09/02 20:27:19 $.)
|