Process Description and Control: Operating Systems: Internals and Design Principles
Process Description and Control: Operating Systems: Internals and Design Principles
Systems:
Internals
and Design Chapter 3
Principles Process Description
and Control
Eighth Edition
By William Stallings
Summary of Earlier
Concepts
A computer platform The OS was developed to
consists of a collection of provide a convenient,
hardware resources feature-rich, secure, and
consistent interface for
Computer applications applications to use
are developed to perform
some task We can think of the OS as
providing a uniform,
abstract representation of
It is inefficient for resources that can be
applications to be written requested and accessed by
directly for a given
hardware platform applications
OS Management of
Application Execution
Resources are made available to multiple
applications
Theprocessor is switched among multiple
applications so all will appear to be
progressing
The processor and I/O devices can be used
efficiently
Process Elements
Two essential elements of a process are:
Program code
• which may be shared with other processes that are executing the
same program
identifier
program
state priority
counter
State
Block Priority
Program counter
Memory pointers
I/O status
It is possible to interrupt a running information
Trace
Process 5000
Process A
Execution 8000
Process B
12000
Process C
Dispatch
Pause
Queue
Enter Dispatch Exit
Processor
Pause
Pause
Queue
Enter Dispatch Exit
Processor
Pause
Table3.2 Time limit exceeded The process has run longer than the specified total time limit. There are a
number of possibilities for the type of time that is measured. These include total
elapsed time ("wall clock time"), amount of time spent executing, and, in the
case of an interactive process, the amount of time since the user last provided
any input.
Reasons for Memory unavailable The process requires more memory than the system can provide.
Protection error
The process tries to access a memory location that it is not allowed to access.
The process attempts to use a resource such as a file that it is not allowed to use,
Time overrun The process has waited longer than a specified maximum for a certain event to
occur.
I/O failure An error occurs during input or output, such as inability to find a file, failure to
read or write after a specified maximum number of tries (when, for example, a
defective area is encountered on a tape), or invalid operation (such as reading
from the line printer).
Invalid instruction The process attempts to execute a nonexistent instruction (often a result of
branching into a data area and attempting to execute the data).
Privileged instruction The process attempts to use an instruction reserved for the operating system.
Operator or OS intervention For some reason, the operator or the operating system has terminated the process
(e.g., if a deadlock exists).
Parent termination When a parent terminates, the operating system may automatically terminate all
of the offspring of that parent.
(Table is located on page 115 Parent request A parent process typically has the authority to terminate any of its offspring.
in the textbook)
Five-State Process Model
Dispatch
Admit Release
New Ready Running Exit
Timeout
Event
Occurs Event
Wait
Blocked
Process B
Process C
Dispatcher
0 5 10 15 20 25 30 35 40 45 50
Timeout
Blocked Queue
Event Event Wait
Occurs
(a) Single blocked queue
Timeout
Event 1 Queue
Event 1 Event 1 Wait
Occurs
Event 2 Queue
Event 2 Event 2 Wait
Occurs
Event n Queue
Event n Event n Wait
Occurs
Occurs
Event
Suspend
Suspend Blocked
New
Activate Dispatch
Ready/ Release
Suspend Ready Running Exit
Suspend Timeout
Occurs
Occurs
Event
Event
Activate
Blocked/
Suspend
Blocked
Suspend
Ad mi t Di s patc h
R eleas e
New Re ady Ru nn in g E xit
Ti me out
Ocurs
Event
Su spe nd
S uspe nd B l ock ed
Ne w
Ocurs
Event
Event
A cti vate
B loc ke d /
B l ock ed
Su sp e n d
S usp end
(b ) Wi th T wo S u sp en d Stat es
Occurs
Event
Suspend
Suspend Blocked
New
Activate Dispatch
Ready/ Release
Suspend Ready Running Exit
Suspend Timeout
Occurs
Occurs
Event
Event
Activate
Blocked/
Suspend
Blocked
Suspend
Computer
Resources
Main
Processor I/O I/O I/O
Memory
Figure 3.10 Processes and Resources (resource allocation at one snapshot in time)
Process
Image
Memory Tables
Process
Memory 1
Files
Process 1
Process 2
Process
Process 3 Image
Process
n
Process n
• existence of files
• location on secondary memory
• current status
• other attributes
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.
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 129 in the
textbook)
Process Control Information
Memory Management
This section may include pointers to segment and/or page tables that describe the virtual memory
assigned to this process.
pointers Progr ●
contains condition
am
• stack
Consists codes plus other
of the status information
registers
contents status status ●
EFLAGS register is
of an example of a
processor
• control and
word PSW used by any
registers registers
• user-visible (PSW OS running on an
x86 processor
)
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
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.
SF (Sign flag)
Control Flag
DF (Direction flag)
Determines whether string processing instructions increment or decrement the 16-bit half-registers SI and
EFLAGS DI (for 16-bit operations) or the 32-bit registers ESI and EDI (for 32-bit operations).
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 131 in the textbook)
Process Control
Information
The additional information needed
by the OS to control and
coordinate the various active
processes
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
Ready
Blocked
Support Functions
•Interrupt handling
•Accounting
•Monitoring
Process Creation
Once the OS decides to create a new process it:
assigns a unique process identifier to the new
process
Execution
Kernel
of the P1
OS
Func-
P2
OS
Func-
Pn
OS
Func-
Operating System
tions tions tions
P1 P2 Pn OS1 OSk
Execution Within
Information Block
Process Control
Information
Private User
Address Space
(Programs, Data)
Kernel Stack
Shared Address
Space
User Processes
operate in user mode to execute user programs and utilities
operate in kernel mode to execute instructions that belong to the kernel
enter kernel mode by issuing a system call, when an exception is generated, or
when an interrupt occurs
Table 3.9 UNIX Process States
fork
Created
Preempted
User
Running preempt
swap out
return Ready to Run Ready to Run
reschedule
In Memory Swapped
process swap in
system call,
interrupt Kernel
Running
Table 3.11 Process size Enables the operating system to know how much space to allocate
the process.
UNIX User identifiers The real user ID identifies the user who is responsible for the
running process. The effective user ID may be used by a process
to gain temporary privileges associated with a particular program;
while that program is being executed as part of the process, the
Table Event descriptor Valid when a process is in a sleeping state; when the event occurs,
the process is transferred to a ready-to-run state.
Entry
Priority Used for process scheduling.
P_link Pointer to the next link in the ready queue (valid if process is ready
to execute).