Chapter 6: Structure of Processes
Download
Report
Transcript Chapter 6: Structure of Processes
Chapter 6
Structure of Processes
Process State and Transition
Data Structure for Process
Layout of System Memory
THE DESIGN OF THE UNIX OPERATING SYSTEM
Maurice J. bach Prentice Hall
1
Process States and Transitions
User Running
interrupt,
interrupt return
9
4
Asleep
in
Memory
sleep
swap
out
Sleep, Swapped
7
reschedule
process
3
Ready to
Run in Memory
enough mem
Created
swap
out
wakeup
Preempted
Kernel
Running
preempt
wakeup
6
return
to user
return
2
Zombie
1
system call,
interrupt
8
swap
in
5
fork
not enough mem
(swapping system only)
Ready to Run, Swapped
2
Data Structures for Process
Kernel Process
Table
Kernel Region
Table
A Process
Per Process Region Table
Text
File Descriptor Table
Data
Stack
U Area
3
Data Structure for Process (contd.)
per process
region table
Kernel region table
u area
Kernel
process table
main memory
4
State of a Process
– Process table entry
• Contains general fields of processes that must be
always be accessible to the kernel
– U area
• further characteristics of the process only need to be
accessible to the running process itself
5
Process table entry
• State field: user running, kernel running etc.
• Fields that allow the kernel to locate the
process and u area. Requires while context
switch
• Process size : kernel know how much space
to allocate for the process.
• User ID
• Process ID
6
Process table entry (contd.)
• Event descriptor.
– Used when the process is in the "sleep" state.
• Scheduling parameters.
– Allow the kernel to determine the order in which
processes move to the states "kernel running" and "user
running”
• A signal field.
– keeps the signals sent to a process but not yet handled.
• Various timers: process execution time, resource
utilization etc.
7
U Area
• A pointer to the process table entry
• User IDs
• various Timer:
– Execution time in user mode
– Execution Time in kernel mode
• An error field: keeps error during system call
• Return value field: result of system call
8
U Area (contd.)
• I/O parameters
– Amount of data transfer
– Address of source and target etc.
• The current directory and current root
• User file descriptor table
• Limit fields
– Restrict process size
– Restrict size of the file it can write
• The control terminal field:
– login terminal associated with the process, if one exists
• An array indicates how the process wishes to react to
signal
9
Per Process Region Table (Pregion)
• Each pregion entry points to the kernel
region table
• Starting virtual (absolute) address of the
region
• Permission filed:
– read-only, read-write, read-execute
10
Kernel Region table
• Kernel region table contains the pointer to
the page table which keeps the physical
memory address
11
Regions
Region
Per Proc Region Tables
(Virtual Addresses)
Process
A
Text
8K
b
Data 16K
c
Stack32K
a
Text
4K
Process
Data 8K
B
Stack
32K
e
d
<Processes and Regions>
12
Pages and Page Tables
Logical Page Number
0
1
2
3
Physical Page Number
177
54
209
17
13
Pages and Page Tables (contd.)
Per Proc Region Table
Page Tables(Physical Addresses)
Text
8K
empty
Data 32K
137K
Stack 64K
852K
87K
764K
541K
552K
433K
783K
727K
333K
986K
941K
897K
1096K
Virtual Addresses
.
.
.
.
.
.
.
.
2001K
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
<Mapping Virtual Addresses to Physical Address>
14
Rest of the topics in Chapter-6
6.3: Context of a Process
6.4 Saving Context of a Process
6.5 Region and related 7 algorithms
6.6 Sleep and Wakeup
15
6.3: Context of a Process
• User-level context
• Register-level context
• System-level context
16
User-level Context
•
•
•
•
•
Text
Data
User stack
Shared memory
These may be in main memory or in the
swap space
17
Register-level Context
•
•
•
•
Program counter
Processor Status (PS) register
Stack pointer
General purpose registers
18
System-level Context
• Static part
– Process table entry
– U area of a process
– Pregion entries, region tables, page tables:
• Dynamic part
– Kernel stack: Private copy of kernel stack (of a
process)
– A set of layers
• Each system-level context layer contains necessary
info to recover previous layer (including registerlevel context of previous layer)
19
Components of Process Context
20
Handling Interrupts
21
Example of Interrupts
22
Algorithm for System Call
23
Steps for a Context Switch
24
6.5 Algorithms on regions
•
•
•
•
•
•
•
Alloc Region
Attach region
Grow / Shrink region
Load region
Freeing region
Detaching region
Duplicating region
25
Region Table entry
• A ptr to the inode of the file whose content
were originally load into the region
• Region type (text, data, ..)
• Region size
• Location of region in PhyMem
• Status: Locked, in demand, valid, being
loaded into memory
• Ref count: # of processes referencing the
region
26
Allocating a region
27
Example of Attaching an Existing
Text Region
28
Changing region size
29
Example: Growing stack by 1K
30
Loading a region
31
Example: Loading a text region
32
Freeing a region
33
Detaching a region
34
Duplicating a region
35
Example: Duplicating a region
36
Sleep and Wakeup
• Processes sleep on Events
• Events are mapped into addresses
• There are sleep queue based on sleep address
37
38
Sleep Alg. (1)
39
Sleep Alg (2)
40
Wakeup
41
Thank You
42