Operating Systems Internals and Design Principles - Chapter 3 and 4
Operating Systems Internals and Design Principles - Chapter 3 and 4
Chapter 3 and 4
Operating Systems:
Internals and Design Principles, 9/E
William Stallings
Process
•A program in execution
•An instance of a program running on a
computer (cooking vs. recipe)
•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, and an associated set of
system resources
Requirements of an Operating System
exec
Process Termination
•Normal completion
•Time limit exceeded
•Privileged instructions in user mode
•Parent termination
•Operator or OS intervention (e.g. deadlock)
•Errors
–memory unavailable
–bounds violation
–protection error
–arithmetic error
–I/O failure
Multiple Blocked Queues
Suspended Processes
•Processor is faster than I/O so many
processes could be waiting for I/O
•Swap these processes to disk to free up
more memory
•Blocked state becomes suspend state
when swapped to disk
•Two new states
–Blocked/Suspend
–Ready/Suspend
Two Suspend States
Operating System Control
Structures
•Information about the current status of
processes and resources
•Tables are constructed for each entity the
operating system manages: memory table,
I/O table, file table
Memory Tables
•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 table)
I/O Tables
•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
File Tables
•Existence of files
•Location on secondary memory
•Current status
•Attributes
•Sometimes this information is maintained
by a file management system
OS Control Tables
Process Table – Process Control Block
•Identifiers: process id, parent process, user
id
•User-visible registers
•Control and status registers: PC, PSW
•Stack pointer
•Scheduling and state info: process state,
priority, used CPU time, event (waiting for)
•Process privileges
•Memory management: pointers to
segments, page table
•Resource ownership and utilization
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
• Mode switch
Process Creation
•Assign a unique process identifier
•Allocate memory space for the process
•Initialize process control block
•Set up appropriate linkages (e.g. put
process in scheduling queue)
•Create or expand other data structures (e.g.
CPU time, page table)
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 – requires I/O
Trap: error or exception occurred; may
cause process to be moved to Exit state
Supervisor/system call, e.g., such as file
open
Change of Process State
1.Save context of processor including
program counter and other registers
2.Update the process control blocks
3.Move process into appropriate queue –
ready; blocked; ready/suspend
4.Run the scheduler to select another
process for execution
5.Update the process control block
6.Restore context of the selected process
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 – monolithic
OS
•Execution within user processes
–Operating system software within context of a
user process, e.g. scheduler
•Process-based operating system
• Implement the OS as a collection of system
processes – modular OS
Execution of the Operating System
Processes and Threads
•Resource ownership - process includes a
virtual address space to hold the process
image
•Scheduling/execution- follows an execution
path that may be interleaved with other
processes
•These two characteristics are treated
independently by the operating system
Threads
Process =
resource grouping (code, data, open files,
etc.) +
execution (program counter, registers,
stack)
Multithreading:
•multiple execution takes place in the
same process environment
•co-operation by sharing resources
(address space, open files, etc.)
The Thread Model