0% found this document useful (0 votes)
11 views34 pages

COE628 Week3 Lecture Part I-W2023 (2)

Uploaded by

rheamalana409
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views34 pages

COE628 Week3 Lecture Part I-W2023 (2)

Uploaded by

rheamalana409
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

•Process Manager

•Processes
•Process states
•State-Diagrams
Last Week
•Queuing Models
(mechanism)
•Dispatcher, traces

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Week 3: Agenda

• Part I:
• Operating System Control Tables
• Process Control Structure
• Process control
• Modes of execution
• Process creation
• Process switching
• UNIX SVR4 process management
• Process states
• Process description
• Process control
Process
Image
Memory Tables
Process
Memory 1

Devices I/O Tables

Files

Processes File Tables

Primary Process Table

Process 1

Process 2
Process
Process 3 Image
Process
n

Process n

Figure 3.11 General Structure of Operating System Control Tables


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Memory Tables

• Used to keep track of both


main (real) and secondary
(virtual) memory
• Processes are maintained on
secondary memory using
some sort of virtual memory
or simple swapping
mechanism

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


I/O Tables

• Used by the OS to manage the


I/O devices and channels of
the computer system
• At any given time, an I/O
device may be available or
assigned to a particular
process

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


File Tables

These tables provide information about:

• Existence of files
• Location on secondary memory
• Current status
• Other attributes

• Information may be maintained and used by a file management


system
• In which case the OS has little or no knowledge of files
• In other operating systems, much of the detail of file management
is managed by the OS itself

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Tables

•Must be maintained to manage processes


•There must be some reference to memory, I/O,
and files, directly or indirectly
•The tables themselves must be accessible by the
OS and therefore are subject to memory
management

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Control Structures

To manage • Where the


and control process is located
a process • The attributes of
the process that
the OS are necessary for
must its management
know:

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Control Structures

Process Location Process Attributes

• A process must include a program • Each process has associated with it


or set of programs to be executed a number of attributes that are
• A process will consist of at least used by the OS for process control
sufficient memory to hold the • The collection of program, data,
programs and data of that process stack, and attributes is referred to
• The execution of a program as the process image
typically involves a stack that is • Process image location will depend
used to keep track of procedure on the memory management
calls and parameter passing scheme being used
between procedures

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.4
Typical Elements of a Process Image

User Data
The modifiable part of the user space. May include program data, a user stack area, and
programs that may be modified.

User Program
The program to be executed.

Stack
Each process has one or more last-in-first-out (LIFO) stacks associated with it. A stack is
used to store parameters and calling addresses for procedure and system calls.

Process Control Block


Data needed by the OS to control the process (see Table 3.5).

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Identification Table 3.5
Identifiers
Numeric identifiers that may be stored with the process control block include
Typical
•Identifier of this process
•Identifier of the process that created this process (parent process) Elements
•User identifier

Processor State Information


of a
User-Visible Registers Process
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 Control
some RISC implementations have over 100.

Control and Status Registers Block


These are a variety of processor registers that are employed to control the operation of the processor.
These include (page 1 of 2)
•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

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
(Table is located
the top of the stack.
on page 125 in the
textbook)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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, Table 3.5
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 Typical
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. Elements of a
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 Process Control
exhibit a parent-child (creator-created) relationship with another process. The process control block
may contain pointers to other processes to support these structures.

Interprocess Communication Block


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.
(page 2 of 2)
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 (Table is located
scheduler. on page 125 in the textbook)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Identification
• Each process is assigned a • Memory tables may be
unique numeric identifier organized to provide a map of
• Otherwise there must be a main memory with an indication
mapping that allows the OS to of which process is assigned to
locate the appropriate tables each region
based on the process identifier • Similar references will appear
in I/O and file tables
• Many of the tables controlled
by the OS may use process • When processes communicate
identifiers to cross-reference with one another, the process
process tables identifier informs the OS of the
destination of a particular
communication
• When processes are allowed to
create other processes,
identifiers indicate the parent
and descendents of each
process

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Processor State Information

• User-visible • Contains condition


Consists registers codes plus other
of the • Control and Program status information
contents
status status • EFLAGS register is
of word an example of a
processor registers PSW used by any
registers (PSW)
• Stack OS running on an
pointers x86 processor

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
I
V V
I A V R N O O D I T S Z A P C
0 0 0 0 0 0 0 0 0 0 I I 0 0 0 1
D C M F T P F F F F F F F F F
P F
L

X ID = Identification flag C DF = Direction flag


X VIP = Virtual interrupt pending X IF = Interrupt enable flag
X VIF = Virtual interrupt flag X TF = Trap flag
X AC = Alignment check S SF = Sign flag
X VM = Virtual 8086 mode S ZF = Zero flag
X RF = Resume flag S AF = Auxiliary carry flag
X NT = Nested task flag S PF = Parity flag
X IOPL = I/O privilege level S CF = Carry flag
S OF = Overflow flag

S Indicates a Status Flag


C Indicates a Control Flag
X Indicates a System Flag
Shaded bits are reserved

Figure 3.12 x86 EFLAGS Register


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Status Flags (condition codes)
AF (Auxiliary carry flag)
Represents carrying or borrowing between half-bytes of an 8-bit arithmetic or logic operation using the
AL register.
CF (Carry flag)

Table 3.6 Indicates carrying out or borrowing into the leftmost bit position following an arithmetic operation. Also
modified by some of the shift and rotate operations.
OF (Overflow flag)
Indicates an arithmetic overflow after an addition or subtraction.
PF (Parity flag)
Parity of the result of an arithmetic or logic operation. 1 indicates even parity; 0 indicates odd parity.

x86
SF (Sign flag)
Indicates the sign of the result of an arithmetic or logic operation.
ZF (Zero flag)
Indicates that the result of an arithmetic or logic operation is 0.

Control Flag
DF (Direction flag)

EFLAGS
Determines whether string processing instructions increment or decrement the 16-bit half-registers SI and
DI (for 16-bit operations) or the 32-bit registers ESI and EDI (for 32-bit operations).

System Flags (should not be modified by application programs)


AC (Alignment check)
Set if a word or doubleword is addressed on a nonword or nondoubleword boundary.
ID (Identification flag)

Register
If this bit can be set and cleared, this processor supports the CPUID instruction. This instruction provides
information about the vendor, family, and model.
RF (Resume flag)
Allows the programmer to disable debug exceptions so that the instruction can be restarted after a debug
exception without immediately causing another debug exception.
IOPL (I/O privilege level)
When set, causes the processor to generate an exception on all accesses to I/O devices during protected

Bits
mode operation.
IF (Interrupt enable flag)
When set, the processor will recognize external interrupts.
TF (Trap flag)
When set, causes an interrupt after the execution of each instruction. This is used for debugging.
NT (Nested task flag)
Indicates that the current task is nested within another task in protected mode operation.
VM (Virtual 8086 mode)
Allows the programmer to enable or disable virtual 8086 mode, which determines whether the processor
runs as an 8086 machine.
VIP (Virtual interrupt pending)
Used in virtual 8086 mode to indicate that one or more interrupts are awaiting service.
VIF (Virtual interrupt flag)
Used in virtual 8086 mode instead of IF.
(Table is located on page 127 in the textbook)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Control Information

• The additional information needed by the OS to


control and coordinate the various
active processes

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Process Process
Identification Identification Identification
Process
Processor State Processor State Processor State Control
Information Information Information Block
Process Control Process Control Process Control
Information Information Information

User Stack User Stack User Stack

Private User Private User Private User


Address Space Address Space Address Space
(Programs, Data) (Programs, Data) (Programs, Data)

Shared Address Shared Address Shared Address


Space Space Space

Process 1 Process 2 Process n

Figure 3.13 User Processes in Virtual Memory


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Process
Control Block
Running

Ready

Blocked

Figure 3.14 Process List Structures


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
The Role of the Process Control Block
• The most important data structure in an OS
• Contains all of the information about a process that is
needed by the OS
• Blocks are read and/or modified by virtually every
module in the OS
• Defines the state of the OS
• Difficulty is not access, but protection
• A bug in a single routine could damage process control
blocks, which could destroy the system’s ability to
manage the affected processes
• A design change in the structure or semantics of the
process control block could affect a number of modules
in the OS
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
User Mode System Mode

n Less-privileged mode n More-privileged mode


n User programs n Also referred to as
typically execute in control mode or
this mode kernel mode
n Kernel of the
operating system

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Management

•Process creation and termination


Table 3.7 •Process scheduling and dispatching
•Process switching
•Process synchronization and support for interprocess communication
Typical •Management of process control blocks
Functions Memory Management
of an •Allocation of address space to processes
•Swapping
Operating •Page and segment management
System I/O Management
Kernel •Buffer management
•Allocation of I/O channels and devices to processes

Support Functions

•Interrupt handling
•Accounting
•Monitoring

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


n Once the OS decides to create a new process it:
Assigns a unique process
identifier to the new process

Allocates space for the process

Initializes the process control


block

Sets the appropriate linkages

Creates or expands other data


structures
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 3.8
Mechanisms for Interrupting the
Execution of a Process

Mechanism Cause Use

Interrupt External to the execution of the Reaction to an asynchronous


current instruction external event

Trap Associated with the execution of Handling of an error or an


the current instruction exception condition

Supervisor call Explicit request Call to an operating system


function

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


System Interrupts
Interrupt Trap
n Due to some sort of event n An error or exception
that is external to and condition generated within
independent of the currently
the currently running process
running process
n Clock interrupt n OS determines if the
condition is fatal
n I/O interrupt
n Memory fault n Moved to the Exit state
n Time slice and a process switch
occurs
n The maximum amount of
time that a process can n Action will depend on the
execute before being nature of the error the
interrupted design of the OS
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
If no interrupts are If an interrupt is
pending the processor: pending the processor:

Proceeds to the fetch stage and fetches the


next instruction of the current program in Sets the program counter to the starting
address of an interrupt handler program
the current process

Switches from user mode to kernel mode


so that the interrupt processing code may
include privileged instructions

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


n The steps in Update the
process control Move the process
a full process Save the context of block of the control block of
the processor
switch are: process currently this process to the
in the Running appropriate queue
state

If the currently running process is to be moved to


another state (Ready, Blocked, etc.), then the OS must Select another
make substantial changes in its environment process for
execution

Restore the context


of the processor to
that which existed
at the time the Update memory Update the process
selected process was management data control block of
last switched out structures the process
selected

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Unix SVR4
n Uses the model where most of the OS executes within the
environment of a user process

n System processes run in kernel mode


n Executes operating system code to perform administrative and
housekeeping functions

n User Processes
n Operate in user mode to execute user programs and utilities
n Operate in kernel mode to execute instructions that belong to the kernel
n Enter kernel mode by issuing a system call, when an exception is
generated, or when an interrupt occurs

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.9 UNIX Process States

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


fork

Created
Preempted

return enough not enough memory


to user memory (swapping system only)

User
Running preempt
swap out
return Ready to Run Ready to Run
reschedule
In Memory Swapped
process swap in
system call,
interrupt Kernel
Running

sleep wakeup wakeup


interrupt,
interrupt return exit

Asleep in swap out Sleep,


Zombie
Memory Swapped

Figure 3.17 UNIX Process State Transition Diagram


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
n Process • Allocates a slot in the process table for the new process
1
creation is by
means of the • Assigns a unique process ID to the child process
kernel system 2
call, fork() • Makes a copy of the process image of the parent, with the
3 exception of any shared memory
n When a
process issues a • Increments counters for any files owned by the parent, to
4 reflect that an additional process now also owns those files
fork request,
the OS
• Assigns the child process to the Ready to Run state
performs the 5
following • Returns the ID number of the child to the parent process,
functions: 6 and a 0 value to the child process

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


n After creating the process, the Kernel can do one of the
following, as part of the dispatcher routine:
n Stay in the parent process. Control returns to user mode at the
point of the fork call of the parent.
n Transfer control to the child process. The child process begins
executing at the same point in the code as the parent, namely at
the return from the fork call.
n Transfer control to another process. Both parent and child are
left in the Ready to Run state.

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Summary
n Process description n Process control
n Operating system control n Modes of execution
structures n Process creation
n Process control structures n Process switching

n UNIX SVR4 process


management
n Process states
n Process description
n Process control

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

You might also like