chapter 3 process description and control operating systems: internals and design principles, 6/e...

68
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall

Upload: alanna-banbury

Post on 14-Dec-2015

291 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Chapter 3Process Description and Control

Operating Systems:Internals and Design Principles, 6/E

William Stallings

Patricia RoyManatee Community College, Venice, FL

©2008, Prentice Hall

Page 2: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Major Functions of anOperating 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

Page 3: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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– an associated set of system resources

Page 4: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Elements (I)• Identifier• State• Priority• Program counter• Memory pointers: to code and data

How to describe a process? What elements are included in

it?

Page 5: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Elements (II)• Context data: value of CPU registers• I/O status information

– Outstanding I/O requests– Assigned I/O devices and used files

• Accounting information– Amount of processor time & clock time used– Time limits– Account numbers

Page 6: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Control Block

• Contains the process elements• Created and managed by the operating

system

Page 7: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Control Block

• Allows support for multiple processes

Page 8: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Trace of the Process

• Sequence of instruction that execute for a process

• Dispatcher switches the processor from one process to another

Page 9: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Example Execution

Page 10: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Trace of Process

Page 11: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Combined Trace of Process

Page 12: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Two-State Process Model

• Process may be in one of two states– Running– Not-running

Page 13: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Queuing Diagram

Page 14: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Creation (I)

Page 15: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Example: Application Modularity

Page 16: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Example: Concurrent Server

Dispatcher process

Request dispatched to a worker process Server

Workerprocess

Page 17: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

• 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.

Process Creation (II)

Page 18: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Termination

Page 19: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Termination

Page 20: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Queuing Diagram

Page 21: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Queuing

• Processes– Not-running ready to execute– Not-running block– Dispatcher must scan list to find process not-

running, ready, and in queue the longest

Page 22: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

A Five-State Model

• Running• Ready• Blocked• New• Exit

Page 23: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Five-State Process Model

Page 24: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process States

Page 25: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Using Two Queues

Page 26: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Multiple Blocked Queues

Page 27: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Suspended Processes

• 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

Page 28: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Two Suspend States

Page 29: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Reason for Process Suspension

Page 30: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Processes and Resources

Page 31: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

In-Class Exercise

Running

Blocked Ready

1 23

4

56

1: process blocks for input2: scheduler picks another process3: scheduler picks this process4: input becomes available5: process blocks for input6: input becomes available

Which state transition is impossible?

Page 32: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Page 33: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Operating System Control Structures

• 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

Page 34: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

OS Control Tables

Page 35: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 36: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 37: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 38: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 39: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Tables• Manage processes• What is a process composed of?• Process image is the collection of

program, data, stack, and attributes

Page 40: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Stack

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.

Page 41: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Location

• 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

Page 42: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Process Images

Page 43: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

PCB: Process Control Information

Page 44: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

• 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.

PCB: Process Control Information

Page 45: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 46: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 47: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 48: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 49: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

How to Switch Process?

Page 50: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 51: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

• Restore context of the selected process

Page 52: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 53: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Execution of the Operating System

• Process-based operating system– Implement the OS as a collection of system

processes

Page 54: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Execution of the Operating System

Page 55: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

OS Executes in User Space

Page 56: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

• Process Switch

vs. • Mode Switch

Page 57: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 58: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 59: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Mode Switch• 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

Page 60: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

UNIX Process States

Page 61: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

UNIX Process State Transition Diagram

Page 62: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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.

Page 63: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Page 64: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Reminder

• 13 students still haven’t formed project teams

• Team needs to be formed by this Friday!

Page 65: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Appendix

Page 66: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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

Page 67: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Elements of a Process Control Block

Page 68: Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

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.