CSC 553 Operating Systems
CSC 553 Operating Systems
Let’s Review
• A computer platform consists of a collection
of hardware resources
• Computer applications are developed to
perform some task
• It is inefficient for applications to be written
directly for a given hardware platform
Let’s Review
• The OS was developed to provide a
convenient, feature-rich, secure, and
consistent interface for applications to use
• We can think of the OS as providing a
uniform, abstract representation of
resources that can be requested and
accessed by applications
OS Management of Application
Execution
• Resources are made available to multiple
applications
• The processor 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
– A set of data associated with that code
• when the processor begins to execute the
program code, we refer to this executing
entity as a process
Process Elements
• While the program is executing, this process can
be uniquely characterized by a number of
elements, including:
Identifier
Program
State Priority
counter
Block Priority
Program counter
• Contains the process elements Memory pointers
Process States
Trace Dispatcher
The behavior of an
individual process
by listing the
sequence of Small program
instructions that that switches the
execute for that processor from
process one process to
another
5000
Process A
8000
Process B
12000
Process C
Dispatch
Pause
Pause
Process Parent
spawning Child process
process
• When the • Is the • Is the new
OS creates a original, process
process at creating,
the explicit process
request of
another
process
Process Termination
• There must be a means for a process to indicate its
completion
• A batch job should include a HALT instruction or
an explicit OS service call for termination
• For an interactive application, the action of the
user will indicate when the process is completed
(e.g. log off, quitting an application)
Normal completion The process executes an OS service call to indicate that it has completed
running.
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.
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,
Process
or it tries to use it in an improper fashion, such as writing to a read-only file.
Arithmetic error The process tries a prohibited computation, such as division by zero, or tries to
store numbers larger than the hardware can accommodate.
Termination 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.
Parent request A parent process typically has the authority to terminate any of its offspring.
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
Suspended Processes
• Swapping
– When none of the processes in main memory is in the
Ready state, the OS swaps one of the blocked processes
out on to disk into a suspend queue
This is a queue of existing processes that have
been temporarily kicked out of main memory, or
suspended
The OS then brings in another process from the
suspend queue or it honors a new-process request
Execution then continues with the newly arrived
process
Suspended Processes
• Swapping
– Swapping, however, is an I/O operation
and therefore there is the potential for
making the problem worse, not better.
Because disk I/O is generally the fastest
I/O on a system, swapping will usually
enhance performance
Admit Dispatch
Release
New Ready Running Exit
Timeout
t
ai
Occurs
e
Event
at
W
iv
t
en
ct
A
Ev
Suspend
Suspend Blocked
Ad
t
mi
mi
Ad
Suspe
t
nd
Activate Dispatch
Ready/ Release
Suspend Ready Running Exit
Suspend Timeout
t
ai
Occurs
Occurs
Event
Event
tW
en
Ev
Activate
Blocked/
Suspend
Blocked
Suspend
Characteristics of a Suspended
Process
• The process is not immediately available for
execution
• The process was placed in a suspended state by an
agent: either itself, a parent process, or the OS, for
the purpose of preventing its execution
• The process may or may not be waiting on an
event
• The process may not be removed from this state
until the agent explicitly orders the removal
Reasons for Process Suspension
P1 P2 Pn
Virtual
Memory
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
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
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
File Tables
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 Identification
Identifiers
Numeric identifiers that may be stored with the process control block include
•Identifier of this process
•Identifier of the process that created this process (parent process) Typical
•User identifier
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
the top of the stack.
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.
Process Identification
• Each process is assigned a unique numeric
identifier
– Otherwise there must be a mapping that allows
the OS to locate the appropriate tables based on
the process identifier
• Many of the tables controlled by the OS
may use process identifiers to cross-
reference process tables
Process Identification
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).
Ready
Blocked
Modes of Execution
• User Mode
– Less-privileged mode
– User programs typically execute in this mode
• System Mode
– More-privileged mode
– Also referred to as control mode or kernel
mode
– Kernel of the operating system
Process Management
•Buffer management
Kernel •Allocation of I/O channels and devices to processes
Support Functions
•Interrupt handling
•Accounting
•Monitoring
Process Creation
System Interrupts
• Due to some sort of event that is external to and
independent of the currently running process
– Clock interrupt
– I/O interrupt
– Memory fault
• Time slice
– The maximum amount of time that a process
can execute before being interrupted
System Interrupts - Traps
• An error or exception condition generated within
the currently running process
• OS determines if the condition is fatal
– Moved to the Exit state and a process switch
occurs
– Action will depend on the nature of the error
the design of the OS
Mode Switching
Select another
process for
execution
P1 P2 Pn
Kernel
Execution P1
OS
P2
OS
Pn
OS
Func- Func- Func-
System P1 P2 Pn OS1
Process Control
Information
Shared Address
Space
Unix SVR4
• Uses the model where most of the OS executes
within the environment of a user process
• System processes run in kernel mode
– Executes operating system code to perform
administrative and housekeeping functions
• 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
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
Process table entry Defines state of a process; this information is always accessible to
the operating system
U (user) area Process control information that needs to be accessed only in the
context of the process
Per process region table Defines the mapping from virtual to physical addresses; also
contains a permission field that indicates the type of access
allowed the process: read-only, read-write, or read-execute
Kernel stack Contains the stack frame of kernel procedures as the process
executes in kernel mode
Process size Enables the operating system to know how much space to allocate
the process.
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
UNIX process operates with the effective user ID.
Process identifiers ID of this process; ID of parent process. These are set up when the
Process process enters the Created state during the fork system call.
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).
Process Control
After Creation
• After creating the process the Kernel can do one of the
following, as part of the dispatcher routine:
– Stay in the parent process. Control returns to user
mode at the point of the fork call of the parent.
– 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.
– Transfer control to another process. Both parent and
child are left in the Ready to Run state.